61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package config
|
|
|
|
import (
|
|
"log/slog"
|
|
|
|
_ "github.com/joho/godotenv/autoload"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
func ReadConfigFile(configFile string) {
|
|
setDefaults()
|
|
if configFile != "" {
|
|
slog.Info("reading Config file", "file", configFile)
|
|
viper.SetConfigFile(configFile)
|
|
} else {
|
|
viper.AddConfigPath(".")
|
|
viper.AddConfigPath("/etc/scanfile/")
|
|
viper.SetConfigName("config")
|
|
viper.SetConfigType("toml")
|
|
}
|
|
viper.SetEnvPrefix("SF")
|
|
|
|
viper.ReadInConfig()
|
|
viper.AutomaticEnv()
|
|
if viper.ConfigFileUsed() == "" {
|
|
viper.WriteConfigAs("./config.toml")
|
|
}
|
|
slog.Info("done reading config", "file", viper.ConfigFileUsed())
|
|
}
|
|
|
|
func setDefaults() {
|
|
// Web
|
|
viper.SetDefault("web.port", 8080)
|
|
viper.SetDefault("web.host", "127.0.0.1")
|
|
viper.SetDefault("web.tls", false)
|
|
viper.SetDefault("web.cert", "/etc/ssl/certs/ssl-cert-snakeoil.pem")
|
|
viper.SetDefault("web.key", "/etc/ssl/key/ssl-cert-snakeoil.key")
|
|
viper.SetDefault("web.loghttp", true)
|
|
viper.SetDefault("web.maxfilesizemb", 100)
|
|
// Database
|
|
viper.SetDefault("db.host", "localhost")
|
|
viper.SetDefault("db.port", 5432)
|
|
viper.SetDefault("db.user", "scanfile")
|
|
viper.SetDefault("db.database", "scanfile")
|
|
viper.SetDefault("db.password", "CHANGEME")
|
|
viper.SetDefault("db.debug", false)
|
|
// Others
|
|
viper.SetDefault("processing.oleurl", "http://localhost:5000")
|
|
viper.SetDefault("processing.maxmimesize", "100MB")
|
|
viper.SetDefault("store.path", "./storage/files/")
|
|
viper.SetDefault("debug", false)
|
|
// UI Interface info
|
|
viper.SetDefault("ui.name", "Scanfile")
|
|
viper.SetDefault("ui.byurl", "https://www.jmbit.de")
|
|
viper.SetDefault("ui.byurl", "Johannes Bülow")
|
|
viper.SetDefault("ui.source", "https://git.jmbit.de/jmb/scanfile")
|
|
}
|
|
|
|
func SaveConfig() error {
|
|
return viper.WriteConfig()
|
|
}
|