-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
43 lines (33 loc) · 936 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package config
import (
"encoding/json"
"io/ioutil"
)
// Config is the top level structure of the config.json file.
type Config struct {
Tokens *APITokens `json:"tokens"`
Repos map[string]string `json:"Repos"`
}
// APITokens used to authenticate the bot with various services.
type APITokens struct {
LastFM string `json:"last.fm"`
Discord string `json:"discord"`
}
// Tokens is the set of APITokens read from the config file.
var Tokens *APITokens
// Repos as read from the config file, a map of GitHub repositories full names
// (e.g. ccrama/Slide) to Discord channel IDs.
var Repos map[string]string
// Load the config file located at config.json into the variables exposed by
// this package.
func Load() error {
body, err := ioutil.ReadFile("config.json")
if err != nil {
return err
}
var config Config
err = json.Unmarshal(body, &config)
Tokens = config.Tokens
Repos = config.Repos
return err
}