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