hiling_go/main.go

59 lines
1.1 KiB
Go
Raw Normal View History

2023-09-08 22:25:38 +07:00
package main
import (
2024-02-06 11:55:25 +07:00
"context"
2023-09-08 22:25:38 +07:00
"log"
"git.nochill.in/nochill/hiling_go/api"
db "git.nochill.in/nochill/hiling_go/db/sqlc"
"git.nochill.in/nochill/hiling_go/util"
2024-02-06 11:55:25 +07:00
_ "github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
2023-09-08 22:25:38 +07:00
)
// "database/sql"?
// "git.nochill.in/nochill/naice_pos/util"
func main() {
config, err := util.LoadConfig(".")
if err != nil {
log.Fatal("cannot load config: ", err)
}
2024-02-06 11:55:25 +07:00
// 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)
2023-09-08 22:25:38 +07:00
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)
}
}