Adds implementation for init command

This commit is contained in:
Miguel de la Cruz 2020-02-29 13:33:03 +01:00
parent a289ed12ad
commit 412d82269b
4 changed files with 40 additions and 11 deletions

21
campaign/campaign.go Normal file
View file

@ -0,0 +1,21 @@
package campaign
import (
"encoding/json"
"fmt"
"io/ioutil"
"git.ctrlz.es/mgdelacroix/campaigner/model"
)
func Save(campaign *model.Campaign) error {
marshaledCampaign, err := json.MarshalIndent(campaign, "", " ")
if err != nil {
return err
}
if err := ioutil.WriteFile("./campaign.json", marshaledCampaign, 0600); err != nil {
return fmt.Errorf("cannot save campaign: %w", err)
}
return nil
}