Skip to content

Commit a85b89b

Browse files
committed
Add new save function
1 parent 28fed3d commit a85b89b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

config/config.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,19 @@ func (c *Config) Save() error {
9090

9191
return json.NewEncoder(file).Encode(c)
9292
}
93+
94+
// Identical save function except that it takes the config object as its argument
95+
func Save(c *Config) error {
96+
configPath, err := createIfNotExists()
97+
if err != nil {
98+
return err
99+
}
100+
101+
// open the config file
102+
file, err := os.OpenFile(configPath, os.O_WRONLY, 0644)
103+
if err != nil {
104+
return err
105+
}
106+
107+
return json.NewEncoder(file).Encode(c)
108+
}

0 commit comments

Comments
 (0)