wasmcloud/cmd/wasmc/config.go

41 lines
564 B
Go

package main
import (
"encoding/json"
"os"
)
type Config struct {
Token string
}
func loadConfig() (*Config, error) {
var cfg Config
fin, err := os.Open(*configLocation)
if err != nil {
if os.IsNotExist(err) {
return &cfg, nil
}
return nil, err
}
defer fin.Close()
err = json.NewDecoder(fin).Decode(&cfg)
if err != nil {
return nil, err
}
return &cfg, nil
}
func saveConfig(cfg *Config) error {
fout, err := os.Create(*configLocation)
if err != nil {
return err
}
defer fout.Close()
return json.NewEncoder(fout).Encode(cfg)
}