-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
42 lines (33 loc) · 913 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
package main
import (
"io/ioutil"
"github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2"
)
// Conf holds the global configuration
var Conf *Config
// Config is the format of the config
type Config struct {
AdminPass string `yaml:"admin_pass"`
Teams []struct {
Name string `yaml:"name"`
} `yaml:"teams"`
// Both in minutes
Time int `yaml:"time"`
GraceTime int `yaml:"grace_time"`
Solutions []int `yaml:"solutions"`
DefaultTeamScore int `yaml:"default_team_score"`
DefaultProblemScore int `yaml:"default_problem_score"`
}
func loadConfig(path string) {
logrus.WithField("path", path).Info("Reading config file")
b, err := ioutil.ReadFile(path)
if err != nil {
logrus.WithError(err).Fatal("Failed reading config file")
}
err = yaml.Unmarshal(b, &Conf)
if err != nil {
logrus.WithError(err).Fatal("Failed parsing config file")
}
logrus.Debugf("%#v", Conf)
}