Skip to content

Commit

Permalink
fix: config persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
naiba committed Nov 14, 2024
1 parent 9e730cc commit 60bfb4c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
)
9 changes: 5 additions & 4 deletions model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
}
Expand All @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 60bfb4c

Please sign in to comment.