add migrate old config

This commit is contained in:
yuzuki999
2023-06-02 09:19:37 +08:00
parent 989b4ff13e
commit e263e70f37
5 changed files with 99 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/fsnotify/fsnotify"
"gopkg.in/yaml.v3"
"io"
"log"
"os"
"path"
@@ -39,10 +40,20 @@ func (p *Conf) LoadFromPath(filePath string) error {
if err != nil {
return fmt.Errorf("open config file error: %s", err)
}
err = yaml.NewDecoder(f).Decode(p)
defer f.Close()
content, err := io.ReadAll(f)
if err != nil {
return fmt.Errorf("read file error: %s", err)
}
err = yaml.Unmarshal(content, p)
if err != nil {
return fmt.Errorf("decode config error: %s", err)
}
old := &OldConfig{}
err = yaml.Unmarshal(content, old)
if err == nil {
migrateOldConfig(p, old)
}
return nil
}