hiling_go/main.go

43 lines
830 B
Go
Raw Normal View History

2023-09-08 22:25:38 +07:00
package main
import (
"database/sql"
"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/lib/pq"
)
// "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, err := sql.Open(config.DBDriver, config.DBSource)
if err != nil {
log.Fatal("cannot connect to db: ", err)
}
2023-09-27 21:57:21 +07:00
// limit db connection
dbConn.SetConnMaxLifetime(100)
dbConn.SetMaxOpenConns(100)
2023-09-08 22:25:38 +07:00
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)
}
}