fog/cmd/api/main.go

42 lines
827 B
Go
Raw Normal View History

2024-12-30 06:29:34 +00:00
package main
import (
"log"
2024-12-30 10:02:01 +00:00
"time"
2024-12-30 06:29:34 +00:00
2024-12-30 10:02:01 +00:00
"midnadimple.com/fog/internal/db"
2024-12-30 06:29:34 +00:00
"midnadimple.com/fog/internal/env"
2024-12-30 10:02:01 +00:00
"midnadimple.com/fog/internal/store/postgres"
2024-12-30 06:29:34 +00:00
)
func main() {
cfg := config{
addr: env.GetString("FOG_ADDR", ":8080"),
2024-12-30 10:02:01 +00:00
db: dbConfig{
addr: env.GetString("FOG_DB_ADDR", "postgres://foguser:fogpass@localhost/fog?sslmode=disable"),
maxOpenConns: env.GetInt("FOG_DB_MAX_OPEN_CONNS", 30),
maxIdleConns: env.GetInt("FOG_DB_MAX_IDLE_CONNS", 30),
maxIdleTime: env.GetDuration("FOG_DB_MAX_IDLE_TIME", 15*time.Minute),
},
2024-12-30 06:29:34 +00:00
}
2024-12-30 10:02:01 +00:00
db, err := db.New(
cfg.db.addr,
cfg.db.maxOpenConns,
cfg.db.maxIdleConns,
cfg.db.maxIdleTime,
)
if err != nil {
log.Fatalln(err)
2024-12-30 06:29:34 +00:00
}
2024-12-30 10:02:01 +00:00
store := postgres.NewPostgresStorage(db)
2024-12-30 06:29:34 +00:00
app := &application{
config: cfg,
2024-12-30 10:02:01 +00:00
store: store,
2024-12-30 06:29:34 +00:00
}
log.Fatal(app.run())
}