59 lines
1.1 KiB
Go
Executable File
59 lines
1.1 KiB
Go
Executable File
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
|
|
"git.nochill.in/nochill/hiling_go/api"
|
|
db "git.nochill.in/nochill/hiling_go/db/sqlc"
|
|
"git.nochill.in/nochill/hiling_go/util"
|
|
_ "github.com/jackc/pgx/v5"
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
// "database/sql"?
|
|
|
|
// "git.nochill.in/nochill/naice_pos/util"
|
|
|
|
func main() {
|
|
config, err := util.LoadConfig(".")
|
|
if err != nil {
|
|
log.Fatal("cannot load config: ", err)
|
|
}
|
|
|
|
// dbConn := pgx.ConnConfig{
|
|
// pgconn.Config{
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// dbConfig := pgxpool.Config{
|
|
// MaxConnLifetime: 200,
|
|
// MaxConns: 100,
|
|
// ConnConfig: ,
|
|
// }
|
|
pooConfig, err := pgxpool.ParseConfig(config.DBSource)
|
|
if err != nil {
|
|
log.Fatal("Database error; %w", err)
|
|
}
|
|
pooConfig.MaxConnLifetime = 100
|
|
pooConfig.MaxConns = 100
|
|
dbConn, err := pgxpool.NewWithConfig(context.Background(), pooConfig)
|
|
if err != nil {
|
|
log.Fatal("cannot connect to db: ", err)
|
|
}
|
|
|
|
store := db.NewStore(dbConn)
|
|
server, err := api.NewServer(config, store)
|
|
if err != nil {
|
|
log.Fatal("cannot make server: ", err)
|
|
}
|
|
|
|
err = server.Start(config.ServerAddress)
|
|
if err != nil {
|
|
log.Fatal("cannot start server: ", err)
|
|
}
|
|
|
|
}
|