You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
830 B

package main
import (
"encoding/json"
"fmt"
"os"
"time"
)
// Config is the configuration for the bot
type Config struct {
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"`
Token Token
TokenCreated time.Time
}
func loadConfig(filename string) (*Config, error) {
f, err := os.Open(filename)
if err != nil {
return nil, fmt.Errorf("can't open: %q: %q", filename, err)
}
defer f.Close()
var conf Config
err = json.NewDecoder(f).Decode(&conf)
if err != nil {
return nil, fmt.Errorf("can't read json: %q: %q", filename, err)
}
return &conf, nil
}
func saveConfig(filename string, conf *Config) error {
f, err := os.Create(filename)
if err != nil {
return err
}
defer f.Close()
err = json.NewEncoder(f).Encode(&conf)
if err != nil {
return err
}
return nil
}