2022-05-02 09:35:49 +02:00

62 lines
1.9 KiB
Go

package main
import (
"flag"
"fmt"
"log"
"gitlab.celogeek.com/photos/api/internal/env"
photosapi "gitlab.celogeek.com/photos/api/internal/photos/api"
)
var (
genv = env.New()
listen = fmt.Sprintf("%s:%d", genv.Get("LISTEN_HOST", "[::]"), genv.GetUInt("LISTEN_PORT", 8000))
psqlHost = genv.Get("POSTGRES_HOST", "localhost")
psqlPort = genv.GetUInt("POSTGRES_PORT", 5432)
psqlUser = genv.Get("POSTGRES_USERNAME", "photos")
psqlPassword = genv.Get("POSTGRES_PASSWORD", "")
psqlDatabase = genv.Get("POSTGRES_DATABASE", "photos")
getEnvConfig = false
getCurrentEnvConfig = false
storePath = genv.Get("STORE_PATH", "./data")
)
func main() {
config := &photosapi.ServiceConfig{
DB: &photosapi.DBConfig{},
}
flag.StringVar(&config.Listen, "listen", listen, "Listen address")
flag.StringVar(&config.DB.Host, "psql-host", psqlHost, "postgresql host")
flag.UintVar(&config.DB.Port, "psql-port", psqlPort, "postgresql port")
flag.StringVar(&config.DB.User, "psql-user", psqlUser, "postgresql user")
flag.StringVar(&config.DB.Password, "psql-password", psqlPassword, "postgresql password")
flag.StringVar(&config.DB.Database, "psql-database", psqlDatabase, "postgresql database")
flag.BoolVar(&getEnvConfig, "generate-config", false, "Generate an env config")
flag.BoolVar(&getCurrentEnvConfig, "generate-current-config", false, "Generate an env config with current env")
flag.StringVar(&config.StorePath, "file-path", storePath, "Store path for the files")
flag.Parse()
if getEnvConfig {
for _, r := range genv.Fallback() {
fmt.Printf("%s=%q\n", r.Key, r.Value)
}
return
}
if getCurrentEnvConfig {
for _, r := range genv.Current() {
fmt.Printf("%s=%q\n", r.Key, r.Value)
}
return
}
p := photosapi.New(config)
if err := p.Run(); err != nil {
log.Fatal(err)
}
}