improved logging, start http server right away
This commit is contained in:
37
main.go
37
main.go
@@ -128,7 +128,7 @@ func getPlayer(w http.ResponseWriter, r *http.Request) {
|
||||
id := mux.Vars(r)["id"]
|
||||
tPlayer, err := utils.GetPlayer(db, id, conf.Steam.APIKey, rL)
|
||||
if err != nil {
|
||||
log.Warningf("[GP] Player not found: %+v", err)
|
||||
log.Infof("[GP] Player not found: %+v", err)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
@@ -260,7 +260,7 @@ func postPlayerTrackMe(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", conf.Httpd.CORSAllowDomains)
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
log.Errorf("[postPlayerTrackMe] %+v", err)
|
||||
log.Infof("[PPTM] Unable to parse form data: %v", err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -270,21 +270,21 @@ func postPlayerTrackMe(w http.ResponseWriter, r *http.Request) {
|
||||
shareCode := r.Form.Get("sharecode")
|
||||
|
||||
if id == "" || authCode == "" || !utils.AuthCodeRegEx.MatchString(authCode) {
|
||||
log.Warningf("[PPTM] invalid arguments: %+v, %+v, %+v", id, authCode, shareCode)
|
||||
log.Infof("[PPTM] invalid arguments: %+v, %+v, %+v", id, authCode, shareCode)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
tPlayer, err := utils.GetPlayer(db, id, conf.Steam.APIKey, rL)
|
||||
if err != nil {
|
||||
log.Warningf("[PPTM] player not found: %+v", err)
|
||||
log.Infof("[PPTM] player not found: %+v", err)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = utils.IsAuthCodeValid(tPlayer, db.Lock, conf.Steam.APIKey, shareCode, authCode, rL)
|
||||
if err != nil {
|
||||
log.Warningf("[PPTM] authCode provided for player %s is invalid: %v", id, err)
|
||||
log.Infof("[PPTM] authCode provided for player %s is invalid: %v", id, err)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
@@ -315,7 +315,7 @@ func getMatchParse(w http.ResponseWriter, r *http.Request) {
|
||||
shareCode := mux.Vars(r)["sharecode"]
|
||||
|
||||
if shareCode == "" || !utils.ShareCodeRegEx.MatchString(shareCode) {
|
||||
log.Warningf("[PPTM] invalid arguments")
|
||||
log.Infof("[PPTM] invalid arguments: %s", shareCode)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -343,7 +343,7 @@ func getMatchWeapons(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
matchId, err := strconv.ParseUint(id, 10, 64)
|
||||
if err != nil {
|
||||
log.Warningf("[GM] Error parsing matchID %s: %v", id, err)
|
||||
log.Infof("[GMW] Error parsing matchID %s: %v", id, err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -354,7 +354,7 @@ func getMatchWeapons(w http.ResponseWriter, r *http.Request) {
|
||||
tStats, err := db.Client.Stats.Query().Where(stats.HasMatchesWith(match.ID(matchId))).All(context.Background())
|
||||
db.Lock.RUnlock()
|
||||
if err != nil {
|
||||
log.Warningf("[GMW] match %d not found: %+v", matchId, err)
|
||||
log.Infof("[GMW] match %d not found: %+v", matchId, err)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
@@ -385,7 +385,7 @@ func getMatchWeapons(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
err = utils.SendJSON(mResponse, w)
|
||||
if err != nil {
|
||||
log.Errorf("[GM] JSON: %+v", err)
|
||||
log.Errorf("[GMW] JSON: %+v", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
@@ -401,7 +401,7 @@ func getMatch(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
matchId, err := strconv.ParseUint(id, 10, 64)
|
||||
if err != nil {
|
||||
log.Warningf("[GM] Error parsing matchID %s: %v", id, err)
|
||||
log.Infof("[GM] Unbale to parse matchID %s: %v", id, err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -410,7 +410,7 @@ func getMatch(w http.ResponseWriter, r *http.Request) {
|
||||
tMatch, err := db.Client.Match.Query().Where(match.ID(matchId)).Only(context.Background())
|
||||
db.Lock.RUnlock()
|
||||
if err != nil {
|
||||
log.Warningf("[GM] match %d not found: %+v", matchId, err)
|
||||
log.Infof("[GM] match %d not found: %v", matchId, err)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
@@ -432,7 +432,7 @@ func getMatch(w http.ResponseWriter, r *http.Request) {
|
||||
tStats, err := tMatch.QueryStats().WithPlayers().All(context.Background())
|
||||
db.Lock.RUnlock()
|
||||
if err != nil {
|
||||
log.Errorf("[GM] can't find stats for match %d: %v", tMatch.ID, err)
|
||||
log.Errorf("[GM] Unable to find stats for match %d: %v", tMatch.ID, err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@@ -562,8 +562,8 @@ func main() {
|
||||
if err != nil {
|
||||
log.Panicf("Failed to open database %s: %v", conf.Db.ConnectTo, err)
|
||||
}
|
||||
defer func(dbSQLite *ent.Client) {
|
||||
_ = dbSQLite.Close()
|
||||
defer func(Client *ent.Client) {
|
||||
_ = Client.Close()
|
||||
}(db.Client)
|
||||
|
||||
if err := db.Client.Schema.Create(
|
||||
@@ -605,12 +605,7 @@ func main() {
|
||||
log.Fatalf("Unbale to setup DemoLoader: %v", err)
|
||||
}
|
||||
|
||||
log.Info("Waiting for GC to be ready")
|
||||
for demoLoader.GCReady != true {
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
log.Info("GC ready, starting HTTP server")
|
||||
|
||||
// start housekeeper
|
||||
go housekeeping()
|
||||
|
||||
// Define routes
|
||||
@@ -624,6 +619,8 @@ func main() {
|
||||
loggedRouter := handlers.LoggingHandler(os.Stdout, router)
|
||||
proxyRouter := handlers.ProxyHeaders(loggedRouter)
|
||||
|
||||
log.Info("Start listening...")
|
||||
|
||||
sockets := make([]net.Listener, 0)
|
||||
|
||||
for _, l := range conf.Httpd.Listen {
|
||||
|
Reference in New Issue
Block a user