mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 12:40:11 +00:00
add migrate old config
This commit is contained in:
13
conf/conf.go
13
conf/conf.go
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user