package context import ( "encoding/json" "fmt" "io/ioutil" ) type Cache struct { Token string `json:"Token"` BaseURL string `json:"BaseURL"` OrgName string `json:"OrgName"` RepoExclude string `json:"RepoExclude"` PullBaseBranch string `json:"PullBaseBranch"` } func LoadCache() (cache *Cache) { // default values cache = &Cache{ Token: "XXXXXXXXXXXXXXXXXX", BaseURL: "https://gitlab.com", OrgName: "organisation", RepoExclude: "exclude*", PullBaseBranch: "devel*", } data, err := ioutil.ReadFile(".cache.json") if err != nil { return } var c Cache if err := json.Unmarshal(data, &c); err != nil { return } return &c } func SaveCache(cache *Cache) { data, err := json.Marshal(cache) if err != nil { fmt.Printf("ERROR: marshal cache: %v\n", err) } err = ioutil.WriteFile(".cache.json", data, 0600) if err != nil { fmt.Printf("ERROR: save cache: %v\n", err) } }