discodoc/config.go

28 lines
486 B
Go

2021-09-07 10:52:27 +07:00
package main
import (
"encoding/json"
"log"
"os"
2021-09-07 11:06:42 +07:00
"github.com/pkg/errors"
2021-09-07 10:52:27 +07:00
)
type Configuration struct {
Prefix string `json:"prefix"`
Token string `json:"token"`
}
2021-09-07 11:06:42 +07:00
func config() Configuration {
var config Configuration
2021-09-07 10:52:27 +07:00
fileBytes, err := os.ReadFile("config.json")
if err != nil {
2021-09-07 11:06:42 +07:00
log.Fatal(errors.Wrap(err, "could not open config"))
2021-09-07 10:52:27 +07:00
}
err = json.Unmarshal(fileBytes, &config)
if err != nil {
2021-09-07 11:06:42 +07:00
log.Fatal(errors.Wrap(err, "could not parse config"))
2021-09-07 10:52:27 +07:00
}
2021-09-07 11:06:42 +07:00
return config
2021-09-07 10:52:27 +07:00
}