mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-25 06:16:58 +00:00
WIP
This commit is contained in:
parent
7b3a09d8ac
commit
4a6f56b44b
7 changed files with 54 additions and 34 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue