phoenix/config/main.go

67 lines
1.4 KiB
Go
Raw Normal View History

2023-07-22 11:33:14 +05:00
package config
import (
"github.com/joho/godotenv"
"github.com/kelseyhightower/envconfig"
"github.com/sirupsen/logrus"
)
var Cfg Config
2023-07-22 11:33:14 +05:00
type Config struct {
// A long and random secret string used for authorization.
SecretKey string `required:"true"`
// Path to the sqlite database.
DBPath string `required:"true"`
LogLevel string `default:"warning"`
// Allows you to skip authorization if the "Remote-User" header is specified.
// Don't use it if you don't know why you need it.
HeaderAuth bool `default:"false"`
// Data for the first user.
// Optional, the site also allows you to create the first user.
DefaultUsername string
DefaultPassword string
// Controls the "secure" option for a token cookie.
SecureCookie bool `default:"true"`
2023-11-01 23:18:33 +05:00
// Site title.
2023-11-01 23:18:33 +05:00
Title string `default:"Phoenix"`
2023-11-02 21:20:10 +05:00
// Any supported css value, embedded directly into every page.
FontFamily string `default:"sans-serif"`
2023-07-22 11:33:14 +05:00
}
func GetConfig() (*Config, error) {
err := godotenv.Load()
if err != nil {
logrus.Infof("Config: %v", err)
}
err = envconfig.Process("p", &Cfg)
2023-07-22 11:33:14 +05:00
if err != nil {
return nil, err
}
return &Cfg, nil
2023-07-22 11:33:14 +05:00
}
func (cfg *Config) GetLogLevel() logrus.Level {
switch cfg.LogLevel {
case "debug":
return logrus.DebugLevel
case "info":
return logrus.InfoLevel
case "warning", "warn":
2023-07-22 11:33:14 +05:00
return logrus.WarnLevel
case "error":
return logrus.ErrorLevel
case "fatal":
return logrus.FatalLevel
default:
return logrus.WarnLevel
}
}