updated deps; code cleanup; updated golangci linter conf
This commit is contained in:
39
main.go
39
main.go
@@ -80,6 +80,7 @@ func housekeeping() {
|
||||
_, err = utils.PlayerFromSteam(tPlayerNeedSteamUpdate, db, conf.Steam.APIKey, rL)
|
||||
if err != nil {
|
||||
log.Warningf("[HK] Unable to update profiles from steam: %v", err)
|
||||
goto afterupdate
|
||||
}
|
||||
}
|
||||
err = rdc.Set(&cache.Item{
|
||||
@@ -93,6 +94,7 @@ func housekeeping() {
|
||||
log.Errorf("[HK] Failure setting cache: %v", err)
|
||||
}
|
||||
}
|
||||
afterupdate:
|
||||
|
||||
// mark matches as vac/gameban
|
||||
bPlayers, err := db.Player.Query().
|
||||
@@ -175,7 +177,7 @@ func housekeeping() {
|
||||
continue
|
||||
}
|
||||
|
||||
if v[0].Count < 10 { //nolint:gomnd
|
||||
if v[0].Count < 10 {
|
||||
log.Warningf("[HK] Found match without all players, try to reload it.")
|
||||
tMatch, err := db.Match.Get(context.Background(), mid)
|
||||
if err != nil {
|
||||
@@ -261,11 +263,10 @@ func housekeeping() {
|
||||
|
||||
func getPlayerMeta(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
l := c.Param("limit")
|
||||
|
||||
var limit int
|
||||
var err error
|
||||
if l != "" {
|
||||
if l := c.Param("limit"); l != "" {
|
||||
limit, err = strconv.Atoi(l)
|
||||
if err != nil {
|
||||
log.Infof("[GPM] limit not an int: %v", err)
|
||||
@@ -276,7 +277,7 @@ func getPlayerMeta(c *gin.Context) {
|
||||
limit = 4
|
||||
}
|
||||
|
||||
if limit > 10 { //nolint:gomnd
|
||||
if limit > 10 {
|
||||
log.Infof("[GPM] limit out of bounds: %d", limit)
|
||||
c.Status(http.StatusBadRequest)
|
||||
return
|
||||
@@ -363,10 +364,9 @@ func getPlayerMeta(c *gin.Context) {
|
||||
|
||||
func getPlayer(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
t := c.Param("time")
|
||||
|
||||
var offsetTime time.Time
|
||||
if t != "" {
|
||||
if t := c.Param("time"); t != "" {
|
||||
unixOffset, err := strconv.ParseInt(t, 10, 64)
|
||||
if err != nil {
|
||||
log.Infof("[GP] offset not an int: %v", err)
|
||||
@@ -405,9 +405,9 @@ 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()) //nolint:gomnd
|
||||
Where(match.DateLT(offsetTime)).Order(ent.Desc(match.FieldDate)).Limit(10).All(context.Background())
|
||||
} else {
|
||||
tMatches, err = tPlayer.QueryMatches().Order(ent.Desc(match.FieldDate)).Limit(10).All(context.Background()) //nolint:gomnd
|
||||
tMatches, err = tPlayer.QueryMatches().Order(ent.Desc(match.FieldDate)).Limit(10).All(context.Background())
|
||||
}
|
||||
if err != nil || len(tMatches) == 0 {
|
||||
log.Debugf("[GP] No matches found for player %s", id)
|
||||
@@ -644,7 +644,6 @@ func getMatchRounds(c *gin.Context) {
|
||||
|
||||
func getMatchChat(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
trans := c.Query("translate")
|
||||
|
||||
if id == "" {
|
||||
c.Status(http.StatusBadRequest)
|
||||
@@ -666,7 +665,7 @@ func getMatchChat(c *gin.Context) {
|
||||
log.Debugf("[GMC] Got header %s, selected %s from %v (w: %v)", c.GetHeader("Accept-Language"), lang, tag, weights)
|
||||
|
||||
var translate bool
|
||||
if trans != "" {
|
||||
if trans := c.Query("translate"); trans != "" {
|
||||
translate, err = strconv.ParseBool(trans)
|
||||
if err != nil {
|
||||
c.Status(http.StatusBadRequest)
|
||||
@@ -858,10 +857,8 @@ func getMatchWeapons(c *gin.Context) {
|
||||
}
|
||||
|
||||
func getMatches(c *gin.Context) {
|
||||
t := c.Param("time")
|
||||
|
||||
var offsetTime time.Time
|
||||
if t != "" {
|
||||
if t := c.Param("time"); t != "" {
|
||||
unixOffset, err := strconv.ParseInt(t, 10, 64)
|
||||
if err != nil {
|
||||
log.Infof("[GMS] offset not an int: %v", err)
|
||||
@@ -872,15 +869,15 @@ func getMatches(c *gin.Context) {
|
||||
offsetTime = time.Unix(unixOffset, 0).UTC()
|
||||
}
|
||||
|
||||
var mResponse []*utils.MatchResponse
|
||||
var mResponse []*utils.MatchResponse //nolint:prealloc
|
||||
|
||||
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()) //nolint:gomnd
|
||||
Where(match.DateLT(offsetTime)).Order(ent.Desc(match.FieldDate)).Limit(20).All(context.Background())
|
||||
} else {
|
||||
tMatches, err = db.Match.Query().Order(ent.Desc(match.FieldDate)).Limit(20).All(context.Background()) //nolint:gomnd
|
||||
tMatches, err = db.Match.Query().Order(ent.Desc(match.FieldDate)).Limit(20).All(context.Background())
|
||||
}
|
||||
if err != nil || len(tMatches) == 0 {
|
||||
log.Debug("[GMS] No matches found")
|
||||
@@ -893,7 +890,7 @@ func getMatches(c *gin.Context) {
|
||||
Avg float64 `json:"avg"`
|
||||
MatchID uint64 `json:"match_stats"`
|
||||
}
|
||||
avgRank := 0.0
|
||||
var avgRank float64
|
||||
|
||||
err := iMatch.QueryStats().
|
||||
Where(matchplayer.RankOldNEQ(0)).
|
||||
@@ -953,7 +950,7 @@ func getMatch(c *gin.Context) {
|
||||
MatchID uint64 `json:"match_stats"`
|
||||
}
|
||||
|
||||
avgRank := 0.0
|
||||
var avgRank float64
|
||||
err = tMatch.QueryStats().
|
||||
Where(matchplayer.RankOldNEQ(0)).
|
||||
GroupBy(matchplayer.MatchesColumn).
|
||||
@@ -1202,11 +1199,11 @@ func main() {
|
||||
|
||||
rdc = cache.New(&cache.Options{
|
||||
Redis: rdb,
|
||||
LocalCache: cache.NewTinyLFU(1000, time.Minute), //nolint:gomnd
|
||||
LocalCache: cache.NewTinyLFU(1000, time.Minute),
|
||||
})
|
||||
|
||||
rL = rate.NewLimiter(rate.Limit(conf.Steam.RatePerSecond), 100) //nolint:gomnd
|
||||
shareCodeRL = rate.NewLimiter(rate.Limit(0.2), 1) //nolint:gomnd
|
||||
rL = rate.NewLimiter(rate.Limit(conf.Steam.RatePerSecond), 1000)
|
||||
shareCodeRL = rate.NewLimiter(rate.Limit(0.2), 1) //nolint:gomnd
|
||||
|
||||
// setup GC
|
||||
err = demoLoader.Setup(&csgo.DemoMatchLoaderConfig{
|
||||
|
Reference in New Issue
Block a user