more linter fixes

This commit is contained in:
2022-11-20 18:31:09 +01:00
parent 5b938f4d06
commit 64fd38709b

100
main.go
View File

@@ -105,7 +105,7 @@ func housekeeping() {
Where(
match.And(
match.HasPlayersWith(player.ID(bp.ID)),
match.DateLTE(bp.GameBanDate.AddDate(0, 0, 30)),
match.DateLTE(bp.GameBanDate.AddDate(0, 0, 30)), //nolint:gomnd
)).
SetGamebanPresent(true).Exec(context.Background())
if err != nil {
@@ -117,7 +117,7 @@ func housekeeping() {
Where(
match.And(
match.HasPlayersWith(player.ID(bp.ID)),
match.DateLTE(bp.VacDate.AddDate(0, 0, 30)),
match.DateLTE(bp.VacDate.AddDate(0, 0, 30)), //nolint:gomnd
)).SetVacPresent(true).Exec(context.Background())
if err != nil {
log.Warningf("[HK] Unable to set gameban/vac for match: %v", err)
@@ -152,6 +152,9 @@ func housekeeping() {
// check for inconsistent matches
tMatchIDs, err := db.Match.Query().IDs(context.Background())
if err != nil {
log.Warningf("[HK] Failure trying to get matches: %v", err)
}
for _, mid := range tMatchIDs {
var v []struct {
ID int `json:"match_stats"`
@@ -168,7 +171,7 @@ func housekeeping() {
continue
}
if v[0].Count < 10 {
if v[0].Count < 10 { //nolint:gomnd
log.Warningf("[HK] Found match without all players, try to reload it.")
tMatch, err := db.Match.Get(context.Background(), mid)
if err != nil {
@@ -269,7 +272,7 @@ func getPlayerMeta(c *gin.Context) {
limit = 4
}
if limit > 10 {
if limit > 10 { //nolint:gomnd
log.Infof("[GPM] limit out of bounds: %d", limit)
c.Status(http.StatusBadRequest)
return
@@ -326,6 +329,9 @@ func getPlayerMeta(c *gin.Context) {
for _, p := range append(metaStats.BestMates, metaStats.MostMates...) {
if p.Player.Name == "" {
continue
}
tP, err := utils.Player(db, p.Player.SteamID64, conf.Steam.APIKey, nil)
if err != nil {
log.Warningf("[GPM] Failure getting player: %v", err)
@@ -347,13 +353,11 @@ func getPlayerMeta(c *gin.Context) {
p.Player.VACDate = tP.VacDate.Unix()
}
}
}
c.JSON(http.StatusOK, metaStats)
}
func getPlayer(c *gin.Context) {
id := c.Param("id")
t := c.Param("time")
@@ -396,9 +400,10 @@ func getPlayer(c *gin.Context) {
var tMatches []*ent.Match
if !offsetTime.IsZero() {
tMatches, err = tPlayer.QueryMatches().Where(match.DateLT(offsetTime)).Order(ent.Desc(match.FieldDate)).Limit(10).All(context.Background())
tMatches, err = tPlayer.QueryMatches().
Where(match.DateLT(offsetTime)).Order(ent.Desc(match.FieldDate)).Limit(10).All(context.Background()) //nolint:gomnd
} else {
tMatches, err = tPlayer.QueryMatches().Order(ent.Desc(match.FieldDate)).Limit(10).All(context.Background())
tMatches, err = tPlayer.QueryMatches().Order(ent.Desc(match.FieldDate)).Limit(10).All(context.Background()) //nolint:gomnd
}
if err != nil || len(tMatches) == 0 {
log.Debugf("[GP] No matches found for player %s", id)
@@ -598,16 +603,16 @@ func getMatchRounds(c *gin.Context) {
return
}
matchId, err := strconv.ParseUint(id, 10, 64)
matchID, err := strconv.ParseUint(id, 10, 64)
if err != nil {
log.Infof("[GMR] Error parsing matchID %s: %v", id, err)
c.Status(http.StatusBadRequest)
return
}
tStats, err := db.MatchPlayer.Query().Where(matchplayer.HasMatchesWith(match.ID(matchId))).All(context.Background())
tStats, err := db.MatchPlayer.Query().Where(matchplayer.HasMatchesWith(match.ID(matchID))).All(context.Background())
if err != nil {
log.Infof("[GMR] match %d not found: %+v", matchId, err)
log.Infof("[GMR] match %d not found: %+v", matchID, err)
c.Status(http.StatusNotFound)
return
}
@@ -665,7 +670,7 @@ func getMatchChat(c *gin.Context) {
}
}
matchId, err := strconv.ParseUint(id, 10, 64)
matchID, err := strconv.ParseUint(id, 10, 64)
if err != nil {
log.Infof("[GMC] Error parsing matchID %s: %v", id, err)
c.Status(http.StatusBadRequest)
@@ -674,11 +679,14 @@ func getMatchChat(c *gin.Context) {
resp := map[string][]*utils.ChatResponse{}
if translate {
err = rdc.Get(context.Background(), fmt.Sprintf(utils.MatchChatCacheKey, matchId, lang.String()), &resp)
err = rdc.Get(context.Background(), fmt.Sprintf(utils.MatchChatCacheKey, matchID, lang.String()), &resp)
if err != nil {
tStats, err := db.Messages.Query().Where(messages.HasMatchPlayerWith(matchplayer.HasMatchesWith(match.ID(matchId)))).WithMatchPlayer().All(context.Background())
tStats, err := db.Messages.Query().
Where(messages.HasMatchPlayerWith(matchplayer.HasMatchesWith(match.ID(matchID)))).
WithMatchPlayer().
All(context.Background())
if err != nil {
log.Infof("[GMC] match %d not found: %+v", matchId, err)
log.Infof("[GMC] match %d not found: %+v", matchID, err)
c.Status(http.StatusNotFound)
return
}
@@ -721,7 +729,7 @@ func getMatchChat(c *gin.Context) {
err = rdc.Set(&cache.Item{
Ctx: context.Background(),
Key: fmt.Sprintf(utils.MatchChatCacheKey, matchId, lang.String()),
Key: fmt.Sprintf(utils.MatchChatCacheKey, matchID, lang.String()),
Value: resp,
TTL: time.Hour * 24 * 30,
})
@@ -732,9 +740,12 @@ func getMatchChat(c *gin.Context) {
}
}
} else {
tStats, err := db.Messages.Query().Where(messages.HasMatchPlayerWith(matchplayer.HasMatchesWith(match.ID(matchId)))).WithMatchPlayer().All(context.Background())
tStats, err := db.Messages.Query().
Where(messages.HasMatchPlayerWith(matchplayer.HasMatchesWith(match.ID(matchID)))).
WithMatchPlayer().
All(context.Background())
if err != nil {
log.Infof("[GMC] match %d not found: %+v", matchId, err)
log.Infof("[GMC] match %d not found: %+v", matchID, err)
c.Status(http.StatusNotFound)
return
}
@@ -764,16 +775,16 @@ func getMatchWeapons(c *gin.Context) {
return
}
matchId, err := strconv.ParseUint(id, 10, 64)
matchID, err := strconv.ParseUint(id, 10, 64)
if err != nil {
log.Infof("[GMW] Error parsing matchID %s: %v", id, err)
c.Status(http.StatusBadRequest)
return
}
tStats, err := db.MatchPlayer.Query().Where(matchplayer.HasMatchesWith(match.ID(matchId))).All(context.Background())
tStats, err := db.MatchPlayer.Query().Where(matchplayer.HasMatchesWith(match.ID(matchID))).All(context.Background())
if err != nil {
log.Infof("[GMW] match %d not found: %+v", matchId, err)
log.Infof("[GMW] match %d not found: %+v", matchID, err)
c.Status(http.StatusNotFound)
return
}
@@ -796,15 +807,15 @@ func getMatchWeapons(c *gin.Context) {
}
mWr := map[string]map[string][][]int{}
playerId := strconv.FormatUint(stat.PlayerStats, 10)
playerID := strconv.FormatUint(stat.PlayerStats, 10)
for _, wr := range mWs {
if _, exists := mWr[playerId]; !exists {
mWr[playerId] = map[string][][]int{}
if _, exists := mWr[playerID]; !exists {
mWr[playerID] = map[string][][]int{}
}
victim := strconv.FormatUint(wr.Victim, 10)
mWr[playerId][victim] = append(mWr[playerId][victim], []int{wr.EqType, wr.HitGroup, int(wr.Dmg)})
mWr[playerID][victim] = append(mWr[playerID][victim], []int{wr.EqType, wr.HitGroup, int(wr.Dmg)})
if _, exist := mResponse.EquipmentMap[wr.EqType]; !exist {
mResponse.EquipmentMap[wr.EqType] = common.EquipmentType(wr.EqType).String()
@@ -820,8 +831,8 @@ func getMatchWeapons(c *gin.Context) {
rSprays := map[string]map[int][][]float32{}
for _, spray := range mSprays {
if _, exists := rSprays[playerId]; !exists {
rSprays[playerId] = map[int][][]float32{}
if _, exists := rSprays[playerID]; !exists {
rSprays[playerID] = map[int][][]float32{}
}
bBuf := bytes.NewBuffer(spray.Spray)
@@ -834,7 +845,7 @@ func getMatchWeapons(c *gin.Context) {
}
log.Debugf("%+v", dSpray)
rSprays[playerId][spray.Weapon] = dSpray
rSprays[playerID][spray.Weapon] = dSpray
}
mResponse.Spray = append(mResponse.Spray, rSprays)
}
@@ -862,9 +873,10 @@ func getMatches(c *gin.Context) {
var err error
var tMatches []*ent.Match
if !offsetTime.IsZero() {
tMatches, err = db.Match.Query().Where(match.DateLT(offsetTime)).Order(ent.Desc(match.FieldDate)).Limit(20).All(context.Background())
tMatches, err = db.Match.Query().
Where(match.DateLT(offsetTime)).Order(ent.Desc(match.FieldDate)).Limit(20).All(context.Background()) //nolint:gomnd
} else {
tMatches, err = db.Match.Query().Order(ent.Desc(match.FieldDate)).Limit(20).All(context.Background())
tMatches, err = db.Match.Query().Order(ent.Desc(match.FieldDate)).Limit(20).All(context.Background()) //nolint:gomnd
}
if err != nil || len(tMatches) == 0 {
log.Debug("[GMS] No matches found")
@@ -879,7 +891,11 @@ func getMatches(c *gin.Context) {
}
avgRank := 0.0
err := iMatch.QueryStats().Where(matchplayer.RankOldNEQ(0)).GroupBy(matchplayer.MatchesColumn).Aggregate(ent.Mean(matchplayer.FieldRankOld)).Scan(context.Background(), &v)
err := iMatch.QueryStats().
Where(matchplayer.RankOldNEQ(0)).
GroupBy(matchplayer.MatchesColumn).
Aggregate(ent.Mean(matchplayer.FieldRankOld)).
Scan(context.Background(), &v)
if err != nil || len(v) == 0 {
log.Debugf("[GMS] Unable to calc avg rank for match %d: %v", iMatch.ID, err)
avgRank = 0.0
@@ -914,16 +930,16 @@ func getMatch(c *gin.Context) {
return
}
matchId, err := strconv.ParseUint(id, 10, 64)
matchID, err := strconv.ParseUint(id, 10, 64)
if err != nil {
log.Infof("[GM] Unable to parse matchID %s: %v", id, err)
c.Status(http.StatusBadRequest)
return
}
tMatch, err := db.Match.Query().Where(match.ID(matchId)).Only(context.Background())
tMatch, err := db.Match.Query().Where(match.ID(matchID)).Only(context.Background())
if err != nil {
log.Infof("[GM] match %d not found: %v", matchId, err)
log.Infof("[GM] match %d not found: %v", matchID, err)
c.Status(http.StatusNotFound)
return
}
@@ -934,7 +950,11 @@ func getMatch(c *gin.Context) {
}
avgRank := 0.0
err = tMatch.QueryStats().Where(matchplayer.RankOldNEQ(0)).GroupBy(matchplayer.MatchesColumn).Aggregate(ent.Mean(matchplayer.FieldRankOld)).Scan(context.Background(), &v)
err = tMatch.QueryStats().
Where(matchplayer.RankOldNEQ(0)).
GroupBy(matchplayer.MatchesColumn).
Aggregate(ent.Mean(matchplayer.FieldRankOld)).
Scan(context.Background(), &v)
if err != nil || len(v) == 0 {
log.Debugf("[GM] Unable to calc avg rank for match %d: %v", tMatch.ID, err)
avgRank = 0
@@ -1106,10 +1126,10 @@ func main() {
rdc = cache.New(&cache.Options{
Redis: rdb,
LocalCache: cache.NewTinyLFU(1000, time.Minute),
LocalCache: cache.NewTinyLFU(1000, time.Minute), //nolint:gomnd
})
rL = rate.NewLimiter(rate.Limit(conf.Steam.RatePerSecond), 100)
rL = rate.NewLimiter(rate.Limit(conf.Steam.RatePerSecond), 100) //nolint:gomnd
// setup GC
err = demoLoader.Setup(&csgo.DemoMatchLoaderConfig{
@@ -1135,7 +1155,7 @@ func main() {
r := gin.New()
r.Use(gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string {
return fmt.Sprintf("%s - - \"%s %s %s\" %d %d \"%s\" \"%s\" %s %s\n",
return fmt.Sprintf("%s - - \"%s %s %s\" %d %d %q %q %s %s\n",
utils.RealIP(&param.Request.Header, param.Request.RemoteAddr),
param.Method,
param.Path,
@@ -1192,7 +1212,7 @@ func main() {
log.Infof("Listening on %s:%d", l.Host, l.Port)
tL, err := net.Listen("tcp", fmt.Sprintf("%s:%d", l.Host, l.Port))
if err != nil {
log.Fatalf("Failure listing on %s:%d: %v", l.Host, l.Port, err)
log.Panicf("Failure listing on %s:%d: %v", l.Host, l.Port, err)
}
go func() {
srv := &http.Server{
@@ -1217,7 +1237,7 @@ killLoop:
case <-reloadSignals:
confStr, err := os.ReadFile(*configFlag)
if err != nil {
log.Fatalf("Unable to open config: %v", err)
log.Panicf("Unable to open config: %v", err)
}
err = yaml.Unmarshal(confStr, &conf)