-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
37 lines (31 loc) · 820 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
package main
import (
"encoding/json"
"fmt"
"io"
"os"
)
type Config struct {
DiscordBotToken string `json:"discord_bot_token"`
DiscordChannelID string `json:"discord_channel_id"`
GithubOAuthToken string `json:"github_oauth_token"`
SlackChannelID string `json:"slack_channel_id"`
SlackOAuthToken string `json:"slack_oauth_token"`
}
func readConfig() (Config, error) {
var config Config
file, err := os.Open("config.json")
if err != nil {
return config, fmt.Errorf("could not open config file: %v", err)
}
defer file.Close()
bytes, err := io.ReadAll(file)
if err != nil {
return config, fmt.Errorf("could not read config file: %v", err)
}
err = json.Unmarshal(bytes, &config)
if err != nil {
return config, fmt.Errorf("could not unmarshal config JSON: %v", err)
}
return config, nil
}