clonepack/config/config.go
GnomeZworc 87fe581353
add a simple auth function
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2026-04-25 23:49:56 +02:00

58 lines
1.1 KiB
Go

package config
import (
"log/slog"
"time"
)
type Config struct {
Server ServerConfig `mapstructure:"server"`
DB DBConfig `mapstructure:"db"`
DataDir string `mapstructure:"data_dir"`
Sync SyncConfig `mapstructure:"sync"`
Log LogConfig `mapstructure:"log"`
Auth AuthConfig `mapstructure:"auth"`
}
type ServerConfig struct {
Host string `mapstructure:"host"`
Port int `mapstructure:"port"`
}
type DBConfig struct {
Path string `mapstructure:"path"`
}
type SyncConfig struct {
Interval string `mapstructure:"interval"`
}
type LogConfig struct {
Level string `mapstructure:"level"`
Format string `mapstructure:"format"`
}
type AuthConfig struct {
LocalhostPrivileged bool `mapstructure:"localhost_privileged"`
}
func (l LogConfig) SlogLevel() slog.Level {
switch l.Level {
case "debug":
return slog.LevelDebug
case "warn", "warning":
return slog.LevelWarn
case "error":
return slog.LevelError
default:
return slog.LevelInfo
}
}
func (s SyncConfig) IntervalDuration() time.Duration {
d, err := time.ParseDuration(s.Interval)
if err != nil || d <= 0 {
return time.Hour
}
return d
}