Skip to content

Commit

Permalink
fix: fixing add point fucntion issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kehiy committed Dec 19, 2023
1 parent 55b4ec0 commit 02f38f0
Showing 1 changed file with 21 additions and 25 deletions.
46 changes: 21 additions & 25 deletions discord/referral.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,27 @@ func (rs *ReferralStore) GetAllReferrals() []*Referral {

// AddPoint add one point for a referral.
func (rs *ReferralStore) AddPoint(code string) bool {
entry, found := rs.syncMap.Load(code)
if !found {
return false
}

if found {
referral := entry.(*Referral)
referral.Points++
rs.syncMap.Store(referral.ReferralCode, referral)
return true
}

// save record
data, err := marshaReferralJSON(rs.syncMap)
if err != nil {
log.Printf("error marshalling validator data file: %v", err)
return false
}

if err := os.WriteFile(rs.cfg.ReferralDataPath, data, 0o600); err != nil {
log.Printf("failed to write to %s: %v", rs.cfg.ReferralDataPath, err)
return false
}

return false
entry, found := rs.syncMap.Load(code)

Check failure on line 98 in discord/referral.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
if !found {
return false
}
referral := entry.(*Referral)
referral.Points++
rs.syncMap.Store(referral.ReferralCode, referral)

// save record

Check failure on line 106 in discord/referral.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
data, err := marshaReferralJSON(rs.syncMap)
if err != nil {
log.Printf("error marshalling validator data file: %v", err)
return false
}

if err := os.WriteFile(rs.cfg.ReferralDataPath, data, 0o600); err != nil {

Check failure on line 113 in discord/referral.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
log.Printf("failed to write to %s: %v", rs.cfg.ReferralDataPath, err)
return false
}

return true
}

func marshaReferralJSON(m *sync.Map) ([]byte, error) {
Expand Down

0 comments on commit 02f38f0

Please sign in to comment.