func main() { goriot.SetAPIKey(ApiKey) goriot.SetLongRateLimit(500, 10*time.Minute) goriot.SetSmallRateLimit(10, 10*time.Second) usage := `OLS CLI Usage: ols-cli user new <name> <ign> ols-cli team score <name> [--win|--lose] ols-cli team new_score <wins> <losses> ols-cli team name <name> <newname> ols-cli team stats ols-cli team remove <team> <id> ols-cli team add <team> <id> ols-cli db dump <olsfile> ols-cli db upload <olsfile> ols-cli db atomic_delete ols-cli update names ols-cli update tiers ols-cli update teams ols-cli matches ols-cli error names ols-cli player <upload> ols-cli captain <upload> ` arguments, _ := docopt.Parse(usage, nil, true, "ols-cli 1.0", false) for _, cmd := range cmds { if cmd.Runnable(arguments) { cmd.Cmd(arguments) } } }
func main() { goptions.ParseAndFail(&options) goriot.SetAPIKey(options.APIKey) session, err := mgo.Dial(options.MongoDB) if err != nil { log.Fatalf("Could not connect to MongoDB: %s", err) } db = session.DB("") r := httptools.NewRegexpSwitch(map[string]http.Handler{ "/([a-z]+)/([0-9]+)/parse": httptools.L{ httptools.SilentHandler(http.HandlerFunc(whitelistHandler)), httptools.L{ httptools.SilentHandler(http.HandlerFunc(parseMatchHistory)), http.HandlerFunc(dumpMatchHistory), }, }, "/([a-z]+)/([0-9]+)": httptools.L{ httptools.SilentHandler(http.HandlerFunc(whitelistHandler)), httptools.MethodSwitch{ "POST": httptools.L{ httptools.SilentHandler(http.HandlerFunc(parseMatchHistory)), http.HandlerFunc(saveMatchHistory), }, "GET": httptools.L{ httptools.SilentHandler(http.HandlerFunc(queryMatchHistory)), http.HandlerFunc(dumpMatchHistory), }, }, }, "/.*": http.FileServer(http.Dir(options.StaticContent)), }) addr := fmt.Sprintf("0.0.0.0:%d", options.Port) log.Printf("Starting webserver on %s...", addr) if err := http.ListenAndServe(addr, r); err != nil { log.Fatalf("Could not start webserver: %s", err) } }
func main() { // set loader start time //var startTime string = time.Now().Format(dtFormat) runtime.GOMAXPROCS(runtime.NumCPU()) var config Configuration = openAndReadConfig("config.json") var dbConfig MysqlConfig = config.DbConfig // Make connection dbmap := initDb(dbConfig.Database, dbConfig.Username, dbConfig.Password) defer dbmap.Db.Close() // Goriot setup // TODO: move limits to configuration goriot.SetAPIKey(config.ApiKey) goriot.SetSmallRateLimit(config.Limits.RequestsPerTenSeconds, 10*time.Second) goriot.SetLongRateLimit(config.Limits.RequestsPerTenMinutes, 10*time.Minute) // get channel that streams summoner ids //summoners, gameSummoners := getSummoners(dbmap) summoners1, summoners2 := getSummoners(dbmap) // update summoner information updateSummoners(summoners1, dbmap) // update game information updateGames(summoners2, dbmap) // end loader time and save //var endTime string = time.Now().Format(dtFormat) //saveLoadReport(startTime, endTime, updatedGameCount, dbmap) globalWg.Wait() return }
func main() { file, err := os.OpenFile("log.txt", os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666) if err != nil { panic(err) } log.SetOutput(file) log.Println("Success?") m := martini.Classic() goriot.SetAPIKey(LeagueApiKey) goriot.SetLongRateLimit(LongLeagueLimit, 10*time.Minute) goriot.SetSmallRateLimit(ShortLeagueLimit, 10*time.Second) // Setup middleware to be attached to the controllers on every call. if Debug { InitDebugMiddleware(m) } else { InitMiddleware(m) } teamHandler := func(renderer render.Render) { teams := ols.GetTeamsDAO().All() renderer.JSON(200, teams) } individualTeamHandler := func(params martini.Params, renderer render.Render) { team := ols.GetTeamsDAO().Load(params["name"]) renderer.JSON(200, team) } m.Get("/admin", func(renderer render.Render) { renderer.HTML(200, "admin", 1) }) m.Get("/error", func(urls url.Values, renderer render.Render) { renderer.HTML(200, "error", urls.Get("status")) }) m.Get("/players/:name", func(params martini.Params, renderer render.Render) { normalizedName := params["name"] fmt.Println(normalizedName) player := ols.GetPlayersDAO().LoadNormalizedIGN(normalizedName) fmt.Println(player) displayTeam := ols.GetTeamsDAO().LoadPlayerDisplay(player.Id) fmt.Println(displayTeam) renderer.HTML(200, "team", displayTeam) }) m.Get("/results", func(renderer render.Render) { players := ols.GetPlayersDAO().All() allPlayerDisplay := []ols.PlayerDraftResult{} for _, player := range players { team := ols.GetTeamsDAO().LoadPlayer(player.Id) playerDisplay := ols.PlayerDraftResult{Ign: player.Ign, Team: team.Name, NormalizedIgn: player.NormalizedIgn} allPlayerDisplay = append(allPlayerDisplay, playerDisplay) } renderer.HTML(200, "drafted", allPlayerDisplay) }) m.Get("/teams", teamHandler) m.Get("/team/:name", individualTeamHandler) m.Get("/", func(renderer render.Render) { renderer.HTML(200, "main", 1) }) m.Get("/register", LoginRequired, func(urls url.Values, renderer render.Render) { renderer.HTML(200, "register", Register{Next: urls.Get("next")}) }) m.Get("/oauth2error", func(token oauth2.Tokens, renderer render.Render) { renderer.JSON(200, token) }) m.Get("/rankings", func(renderer render.Render) { players := ols.GetPlayersDAO().All() sort.Sort(players) renderer.HTML(200, "rank", players) }) //m.Get("/draft-socket/:drafter", sockets.JSON(Message{}), func(params martini.Params, receiver <-chan *Message, sender chan<- *Message, done <-chan bool, disconnect chan<- int, errorChannel <-chan error) { //}) m.Get("/register/complete", LoginRequired, func(urls url.Values, renderer render.Render, token oauth2.Tokens, w http.ResponseWriter, r *http.Request) { summonerName := urls.Get("summoner") teamName := urls.Get("team") if token.Expired() { http.Redirect(w, r, "/error?status=InvalidFacebook", 302) return } id, err := GetId(token.Access()) if err != nil { renderer.Status(404) return } normalizedSummonerName := goriot.NormalizeSummonerName(summonerName)[0] player := ols.GetPlayersDAO().LoadNormalizedIGN(normalizedSummonerName) if player.Id == 0 { http.Redirect(w, r, "/error?status=No Player Found", 302) return } user := ols.GetUserDAO().GetUserFB(id) // User is registered registered if user.LeagueId != 0 { http.Redirect(w, r, "/error?status=Already Registered User", 302) return } user = site.User{LeagueId: player.Id, FacebookId: id} log.Println("User registered:", user) team := ols.GetTeamsDAO().LoadPlayerByCaptain(player.Id) newTeam := team if team.Name != "" && teamName != "" { newTeam.Name = teamName ols.GetTeamsDAO().Update(team, newTeam) } ols.GetUserDAO().Save(user) //next := urls.Get("next") log.Println("[REGISTER]: ", teamName) renderer.HTML(200, "register_complete", 1) }) initFunnyRouter(m) SocketRouter(m) err = http.ListenAndServe(":6060", m) // Nginx needs to redirect here, so we don't need sudo priv to test. if err != nil { log.Println(err) } }