config: migrate to new yaml format

config-base.yaml is almost identical to json version, except there's no "order" field, as
"sections" and "settings" fields are now lists themselves and so Go can
parse the correct order. As such, removed enumerate_config.py. Also,
rewrote scripts/generate_ini.py in Go as scripts/ini/. Config structure
in Go form is now in common/config.go, and is used by jfa-go and the ini
script. app.configBase is now untouched once read from config-base.yaml,
and instead copied to and patched in app.patchedConfig. Patching occurs
at program start and config modification, so GetConfig is now just a
couple of lines. Discord role patching still occurs in GetConfig, as the
available roles can change regularly. Also added new "Disabled" field to
sections, to avoid the nightmare of deleting from an array.
This commit is contained in:
Harvey Tindall
2024-08-26 15:43:28 +01:00
parent 711b817cff
commit f063b970b4
17 changed files with 2180 additions and 2566 deletions
+7 -3
View File
@@ -32,6 +32,7 @@ import (
"github.com/hrfee/mediabrowser"
"github.com/lithammer/shortuuid/v3"
"gopkg.in/ini.v1"
"gopkg.in/yaml.v3"
)
var (
@@ -93,7 +94,8 @@ type appContext struct {
config *ini.File
configPath string
configBasePath string
configBase settings
configBase common.Config
patchedConfig common.Config
dataPath string
webFS httpFS
cssClass string // Default theme, "light"|"dark".
@@ -388,9 +390,11 @@ func start(asDaemon, firstCall bool) {
defer app.storage.db.Close()
// Read config-base for settings on web.
app.configBasePath = "config-base.json"
app.configBasePath = "config-base.yaml"
configBase, _ := fs.ReadFile(localFS, app.configBasePath)
json.Unmarshal(configBase, &app.configBase)
yaml.Unmarshal(configBase, &app.configBase)
// copy it to app.patchedConfig, and patch in settings from app.config, and language stuff.
app.PatchConfigBase()
secret, err := generateSecret(16)
if err != nil {