From 7f6f392ab5ba354be8fae0cb3cb288728df1a84e Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Sun, 3 Dec 2017 10:25:07 -0500 Subject: [PATCH] Connect to the DB and pass it to a GameProcessor. --- xonstat/util/xs_glicko.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/xonstat/util/xs_glicko.go b/xonstat/util/xs_glicko.go index 8bdcca4..a90751f 100644 --- a/xonstat/util/xs_glicko.go +++ b/xonstat/util/xs_glicko.go @@ -6,6 +6,9 @@ import ( "fmt" "log" "os" + + "github.com/jmoiron/sqlx" + _ "github.com/lib/pq" ) const DefaultStartGameID = 0 @@ -53,6 +56,29 @@ func loadConfig(path string) (*Config, error) { return config, nil } +type GameProcessor struct { + config *Config + db *sqlx.DB +} + +func NewGameProcessor(config Config) *GameProcessor { + processor := new(GameProcessor) + + db, err := sqlx.Connect("postgres", config.ConnStr) + if err != nil { + log.Fatal(err) + } + processor.db = db + + return processor +} + +func (gp *GameProcessor) GameIDsInRange() []int { + gameIDs := make([]int, 0) + // fetch game_ids using gp.db + return gameIDs +} + func main() { path := flag.String("config", "xs_glicko.json", "configuration file path") start := flag.Int("start", DefaultStartGameID, "starting game_id") @@ -77,5 +103,6 @@ func main() { config.RankingWindowDays = *days } - fmt.Printf("%+v\n", config) + processor := NewGameProcessor(*config) + fmt.Printf("%+v\n", processor) } -- 2.39.2