mirror of
https://github.com/Baipyrus/ProxySwitcher.git
synced 2024-12-26 12:41:45 +00:00
saving new config file only, use name.json as filename
This commit is contained in:
parent
6d4f6db33d
commit
89af1d1cc1
@ -2,6 +2,7 @@ package util
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -47,15 +48,14 @@ func ReadConfigs(cfgPath string) ([]*Config, error) {
|
|||||||
return configs, err
|
return configs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func SaveConfig(name string, config Config) error {
|
func SaveConfig(cfgPath string, config Config) error {
|
||||||
configs, _ := ReadConfigs(name)
|
data, err := json.Marshal(config)
|
||||||
configs = append(configs, &config)
|
|
||||||
|
|
||||||
data, err := json.Marshal(configs)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.WriteFile(name, data, 0666)
|
cfgName := fmt.Sprintf("%s.json", config.Name)
|
||||||
|
cfgFile := filepath.Join(cfgPath, cfgName)
|
||||||
|
err = os.WriteFile(cfgFile, data, 0666)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user