fix: config persistence

This commit is contained in:
naiba 2024-11-14 20:21:02 +08:00
parent 9e730cc2cb
commit 60bfb4cb65
2 changed files with 6 additions and 5 deletions

2
go.mod
View File

@ -37,6 +37,7 @@ require (
golang.org/x/text v0.16.0
google.golang.org/grpc v1.63.0
google.golang.org/protobuf v1.34.2
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/sqlite v1.5.5
gorm.io/gorm v1.25.10
)
@ -86,5 +87,4 @@ require (
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.22.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

View File

@ -6,10 +6,11 @@ import (
"strconv"
"strings"
"github.com/knadh/koanf/parsers/yaml"
kyaml "github.com/knadh/koanf/parsers/yaml"
"github.com/knadh/koanf/providers/env"
"github.com/knadh/koanf/providers/file"
"github.com/knadh/koanf/v2"
"gopkg.in/yaml.v3"
)
var Languages = map[string]string{
@ -121,7 +122,7 @@ func (c *Config) Read(path string) error {
}
if _, err := os.Stat(path); err == nil {
err = c.k.Load(file.Provider(path), yaml.Parser())
err = c.k.Load(file.Provider(path), kyaml.Parser())
if err != nil {
return err
}
@ -137,7 +138,7 @@ func (c *Config) Read(path string) error {
}
if c.Site.Brand == "" {
c.Site.Brand = "NeZha"
c.Site.Brand = "Nezha Monitoring"
}
if c.Site.CookieName == "" {
c.Site.CookieName = "nezha-dashboard"
@ -201,7 +202,7 @@ func (c *Config) updateIgnoredIPNotificationID() {
// Save 保存配置文件
func (c *Config) Save() error {
c.updateIgnoredIPNotificationID()
data, err := c.k.Marshal(yaml.Parser())
data, err := yaml.Marshal(c)
if err != nil {
return err
}