57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
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 {
|
|
Address string
|
|
Path string
|
|
TokenLife int
|
|
}
|
|
}
|
|
|
|
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")
|
|
flag.IntVar(&config.API.TokenLife, "api-token-life", 24*60*60, "API login token lifetime in seconds")
|
|
|
|
if err := envflag.Parse(); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
flag.Parse()
|
|
}
|
|
|
|
return config
|
|
}
|