fix default config value

This commit is contained in:
yusing 2024-03-29 01:38:58 +00:00
parent 77f957c7a8
commit ca98b31458
4 changed files with 11 additions and 6 deletions

Binary file not shown.

View file

@ -22,7 +22,7 @@ services:
- ./config:/app/config
# if local docker provider is used
# - /var/run/docker.sock:/var/run/docker.sock:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
# use existing certificate
# - /path/to/cert.pem:/app/certs/cert.crt:ro

View file

@ -24,10 +24,6 @@ type Config interface {
func NewConfig(path string) Config {
cfg := &config{
m: &configModel{
TimeoutShutdown: 3 * time.Second,
RedirectToHTTPS: false,
},
reader: &FileReader{Path: path},
}
cfg.watcher = NewFileWatcher(
@ -60,7 +56,7 @@ func (cfg *config) Load(reader ...Reader) error {
return NewNestedError("unable to read config file").With(err)
}
model := &configModel{}
model := defaultConfig()
if err := yaml.Unmarshal(data, model); err != nil {
return NewNestedError("unable to parse config file").With(err)
}
@ -188,6 +184,13 @@ type configModel struct {
RedirectToHTTPS bool `yaml:"redirect_to_https" json:"redirect_to_https"`
}
func defaultConfig() *configModel {
return &configModel{
TimeoutShutdown: 3 * time.Second,
RedirectToHTTPS: false,
}
}
type config struct {
m *configModel

View file

@ -37,6 +37,8 @@ func main() {
cfg = NewConfig(configPath)
cfg.MustLoad()
logrus.Info(cfg.Value())
if args.Command == CommandVerify {
logrus.Printf("config OK")
return