mirror of
https://github.com/Baipyrus/ProxySwitcher.git
synced 2024-12-25 12:11:46 +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 (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -47,15 +48,14 @@ func ReadConfigs(cfgPath string) ([]*Config, error) {
|
||||
return configs, err
|
||||
}
|
||||
|
||||
func SaveConfig(name string, config Config) error {
|
||||
configs, _ := ReadConfigs(name)
|
||||
configs = append(configs, &config)
|
||||
|
||||
data, err := json.Marshal(configs)
|
||||
func SaveConfig(cfgPath string, config Config) error {
|
||||
data, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user