szoe-pontok/config/config.go

57 lines
1.4 KiB
Go
Raw Normal View History

2024-10-10 18:22:03 +00:00
package config
import (
"flag"
"github.com/kouhin/envflag"
"github.com/redis/go-redis/v9"
)
type Config struct {
Database struct {
Host string
Port uint
User string
Password string
DBname string
}
Redis redis.Options
API struct {
2024-10-10 19:41:49 +00:00
Address string
Path string
TokenLife int
2024-10-10 18:22:03 +00:00
}
}
var config *Config
func GetConfig() *Config {
if config == nil {
config = &Config{}
flag.StringVar(&config.Database.Host, "db-host", "db", "database host")
flag.UintVar(&config.Database.Port, "db-port", 5432, "database port")
flag.StringVar(&config.Database.User, "db-user", "admin", "database user")
flag.StringVar(&config.Database.Password, "db-password", "admin", "database password")
flag.StringVar(&config.Database.DBname, "db-name", "szoe", "database name")
flag.StringVar(&config.Redis.Addr, "redis-address", "redis:6379", "redis address")
flag.StringVar(&config.Redis.Password, "redis-password", "redis", "redis password")
flag.IntVar(&config.Redis.DB, "redis-db", 0, "redis database")
flag.StringVar(&config.API.Address, "api-address", ":5000", "API address")
flag.StringVar(&config.API.Path, "api-path", "api", "API path root")
2024-10-10 19:41:49 +00:00
flag.IntVar(&config.API.TokenLife, "api-token-life", 24*60*60, "API login token lifetime in seconds")
2024-10-10 18:22:03 +00:00
if err := envflag.Parse(); err != nil {
panic(err)
}
flag.Parse()
}
return config
}