11 const DefaultStartGameID = 0
12 const DefaultEndGameID = -1
13 const DefaultRankingWindowDays = 7
16 // database connection string
19 // the starting game_id in the games table
22 // the ending game_id in the games table
25 // the number of days constituting the ranking window
29 func loadConfig(path string) (*Config, error) {
33 config.ConnStr = "user=xonstat host=localhost dbname=xonstatdb sslmode=disable"
34 config.StartGameID = DefaultStartGameID
35 config.EndGameID = DefaultEndGameID
36 config.RankingWindowDays = DefaultRankingWindowDays
38 file, err := os.Open(path)
40 fmt.Println("Failed opening the file.")
44 decoder := json.NewDecoder(file)
46 // overwrite in-mem config with new values
47 err = decoder.Decode(config)
49 fmt.Println("Failed to decode the JSON.")
57 path := flag.String("config", "xs_glicko.json", "configuration file path")
58 start := flag.Int("start", DefaultStartGameID, "starting game_id")
59 end := flag.Int("end", DefaultEndGameID, "ending game_id")
60 days := flag.Int("days", DefaultRankingWindowDays, "number of days in the ranking window")
63 config, err := loadConfig(*path)
65 log.Fatalf("Unable to load config file: %s.\n", err)
68 if *start != DefaultStartGameID {
69 config.StartGameID = *start
72 if *end != DefaultEndGameID {
73 config.EndGameID = *end
76 if *days != DefaultRankingWindowDays {
77 config.RankingWindowDays = *days
80 fmt.Printf("%+v\n", config)