package gpaste import ( "fmt" "io" "os" "strings" "github.com/pelletier/go-toml" ) type ServerConfig struct { LogLevel string `toml:"LogLevel"` URL string `toml:"URL"` ListenAddr string `toml:"ListenAddr"` Store *ServerStoreConfig `toml:"Store"` } type ServerStoreConfig struct { Type string `toml:"Type"` } func ServerConfigFromReader(r io.Reader) (*ServerConfig, error) { decoder := toml.NewDecoder(r) var c ServerConfig if err := decoder.Decode(&c); err != nil { return nil, fmt.Errorf("error decoding server config: %w", err) } if c.Store == nil { c.Store = &ServerStoreConfig{} } c.updateFromEnv() return &c, nil } func (sc *ServerConfig) updateFromEnv() { if value, ok := os.LookupEnv("GPASTE_LOGLEVEL"); ok { sc.LogLevel = strings.ToUpper(value) } if value, ok := os.LookupEnv("GPASTE_URL"); ok { sc.URL = value } if value, ok := os.LookupEnv("GPASTE_LISTENADDR"); ok { sc.ListenAddr = value } if value, ok := os.LookupEnv("GPASTE_STORE_TYPE"); ok { sc.Store.Type = value } }