using parameter to determine config name/path

This commit is contained in:
Baipyrus 2024-09-13 00:15:56 +02:00
parent c55aec82ce
commit 15e81cf2ea

View File

@ -6,7 +6,7 @@ import (
"os" "os"
) )
func ReadConfigs() ([]*Config, error) { func ReadConfigs(name string) ([]*Config, error) {
file, err := os.Open("configs.json") file, err := os.Open("configs.json")
if err != nil { if err != nil {
@ -25,8 +25,8 @@ func ReadConfigs() ([]*Config, error) {
return config, nil return config, nil
} }
func SaveConfig(config Config) error { func SaveConfig(name string, config Config) error {
configs, _ := ReadConfigs() configs, _ := ReadConfigs(name)
configs = append(configs, &config) configs = append(configs, &config)
data, err := json.Marshal(configs) data, err := json.Marshal(configs)
@ -34,6 +34,6 @@ func SaveConfig(config Config) error {
return err return err
} }
err = os.WriteFile("configs.json", data, 0666) err = os.WriteFile(name, data, 0666)
return err return err
} }