some more code cleanup
This commit is contained in:
28
main.go
28
main.go
@@ -220,17 +220,17 @@ func housekeeping() {
|
||||
shareCodes, err := utils.GetNewShareCodesForPlayer(tPlayer, conf.Steam.APIKey, rL)
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, utils.AuthcodeUnauthorizedError):
|
||||
case errors.Is(err, utils.ErrorAuthcodeUnauthorized):
|
||||
log.Infof("[HK] authCode for player %d is no longer valid", tPlayer.ID)
|
||||
err = tPlayer.Update().ClearAuthCode().ClearSharecodeUpdated().Exec(context.Background())
|
||||
if err != nil {
|
||||
log.Errorf("[HK] Unable to clear authcode for player %d: %v", tPlayer.ID, err)
|
||||
}
|
||||
continue
|
||||
case errors.Is(err, utils.SharecodeNoMatchError):
|
||||
case errors.Is(err, utils.ErrorSharecodeNoMatch):
|
||||
log.Warningf("[HK] last shareCode for player %d does not match player", tPlayer.ID)
|
||||
continue
|
||||
case errors.Is(err, utils.NoMatchError):
|
||||
case errors.Is(err, utils.ErrorNoMatch):
|
||||
log.Infof("[HK] tracked player %d with no matches found, untracked", tPlayer.ID)
|
||||
err = tPlayer.Update().ClearAuthCode().ClearSharecodeUpdated().Exec(context.Background())
|
||||
if err != nil {
|
||||
@@ -413,7 +413,7 @@ func getPlayer(c *gin.Context) {
|
||||
|
||||
for _, iMatch := range tMatches {
|
||||
mResponse := &utils.MatchResponse{
|
||||
MatchId: iMatch.ID,
|
||||
MatchID: iMatch.ID,
|
||||
Map: iMatch.Map,
|
||||
Date: iMatch.Date.Unix(),
|
||||
Score: [2]int{iMatch.ScoreTeamA, iMatch.ScoreTeamB},
|
||||
@@ -490,7 +490,7 @@ func deletePlayerTrack(c *gin.Context) {
|
||||
|
||||
_, err = utils.IsAuthCodeValid(tPlayer, conf.Steam.APIKey, "", authCode, nil)
|
||||
if err != nil {
|
||||
if errors.Is(err, utils.AuthcodeUnauthorizedError) {
|
||||
if errors.Is(err, utils.ErrorAuthcodeUnauthorized) {
|
||||
log.Infof("[DPT] authCode provided for player %s is invalid: %v", id, err)
|
||||
c.Status(http.StatusUnauthorized)
|
||||
return
|
||||
@@ -540,11 +540,11 @@ func postPlayerTrack(c *gin.Context) {
|
||||
_, err = utils.IsAuthCodeValid(tPlayer, conf.Steam.APIKey, shareCode, authCode, rL)
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, utils.AuthcodeUnauthorizedError):
|
||||
case errors.Is(err, utils.ErrorAuthcodeUnauthorized):
|
||||
log.Infof("[PPT] authCode provided for player %s is invalid: %v", id, err)
|
||||
c.Status(http.StatusUnauthorized)
|
||||
return
|
||||
case errors.Is(err, utils.SharecodeNoMatchError):
|
||||
case errors.Is(err, utils.ErrorSharecodeNoMatch):
|
||||
log.Infof("[PPT] shareCode provided for player %s (%s) is invalid: %v", id, shareCode, err)
|
||||
c.Status(http.StatusPreconditionFailed)
|
||||
return
|
||||
@@ -904,7 +904,7 @@ func getMatches(c *gin.Context) {
|
||||
}
|
||||
|
||||
mResponse = append(mResponse, &utils.MatchResponse{
|
||||
MatchId: iMatch.ID,
|
||||
MatchID: iMatch.ID,
|
||||
Map: iMatch.Map,
|
||||
Date: iMatch.Date.Unix(),
|
||||
Score: [2]int{iMatch.ScoreTeamA, iMatch.ScoreTeamB},
|
||||
@@ -963,7 +963,7 @@ func getMatch(c *gin.Context) {
|
||||
}
|
||||
|
||||
mResponse := &utils.MatchResponse{
|
||||
MatchId: tMatch.ID,
|
||||
MatchID: tMatch.ID,
|
||||
ShareCode: tMatch.ShareCode,
|
||||
Map: tMatch.Map,
|
||||
Date: tMatch.Date.Unix(),
|
||||
@@ -1088,18 +1088,18 @@ func main() {
|
||||
journalhook.Enable()
|
||||
}
|
||||
|
||||
if conf.Db.Driver == "pgx" {
|
||||
pdb, err := sql.Open("pgx", conf.Db.ConnectTo)
|
||||
if conf.DB.Driver == "pgx" {
|
||||
pdb, err := sql.Open("pgx", conf.DB.ConnectTo)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to open database %s: %v", conf.Db.ConnectTo, err)
|
||||
log.Fatalf("Failed to open database %s: %v", conf.DB.ConnectTo, err)
|
||||
}
|
||||
|
||||
drv := sql.OpenDB(dialect.Postgres, pdb.DB())
|
||||
db = ent.NewClient(ent.Driver(drv))
|
||||
} else {
|
||||
db, err = ent.Open(conf.Db.Driver, conf.Db.ConnectTo)
|
||||
db, err = ent.Open(conf.DB.Driver, conf.DB.ConnectTo)
|
||||
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(Client *ent.Client) {
|
||||
_ = Client.Close()
|
||||
|
Reference in New Issue
Block a user