65 lines
1.4 KiB
Go
Executable File
65 lines
1.4 KiB
Go
Executable File
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
|
|
"git.nochill.in/nochill/hiling_go/api"
|
|
db "git.nochill.in/nochill/hiling_go/db/repository"
|
|
_ "git.nochill.in/nochill/hiling_go/docs"
|
|
"git.nochill.in/nochill/hiling_go/util"
|
|
_ "github.com/jackc/pgx/v5"
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
// @title Hiling API
|
|
// @version 1.0
|
|
// @description REST API for Hiling — a location review and discovery platform.
|
|
// @host localhost:8888
|
|
// @BasePath /
|
|
// @securityDefinitions.apikey CookieAuth
|
|
// @in cookie
|
|
// @name paseto
|
|
|
|
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)
|
|
}
|
|
|
|
}
|