This commit is contained in:
crapStone 2024-01-18 21:22:19 +01:00
parent 7b3a09d8ac
commit 4a6f56b44b
No known key found for this signature in database
GPG key ID: 22D4BF0CF7CC29C8
7 changed files with 54 additions and 34 deletions

View file

@ -4,6 +4,7 @@ import (
"os"
"path"
"github.com/creasty/defaults"
"github.com/pelletier/go-toml/v2"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
@ -13,10 +14,23 @@ var ALWAYS_BLACKLISTED_PATHS = []string{
"/.well-known/acme-challenge/",
}
func NewDefaultConfig() Config {
config := Config{}
if err := defaults.Set(&config); err != nil {
panic(err)
}
// defaults does not support setting arrays from strings
config.Server.PagesBranches = []string{"main", "master", "pages"}
return config
}
func ReadConfig(ctx *cli.Context) (*Config, error) {
config := NewDefaultConfig()
// if config is not given as argument return empty config
if !ctx.IsSet("config-file") {
return &Config{}, nil
return &config, nil
}
configFile := path.Clean(ctx.String("config-file"))
@ -27,9 +41,8 @@ func ReadConfig(ctx *cli.Context) (*Config, error) {
return nil, err
}
config := &Config{}
err = toml.Unmarshal(content, config)
return config, err
err = toml.Unmarshal(content, &config)
return &config, err
}
func MergeConfig(ctx *cli.Context, config *Config) {