Skip to content

Commit

Permalink
mutex in handler struct
Browse files Browse the repository at this point in the history
  • Loading branch information
kevkevinpal committed May 21, 2024
1 parent 8d4f1d3 commit e6e7deb
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions handlers/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ type bountyHandler struct {
generateBountyResponse func(bounties []db.NewBounty) []db.BountyResponse
userHasAccess func(pubKeyFromAuth string, uuid string, role string) bool
userHasManageBountyRoles func(pubKeyFromAuth string, uuid string) bool
m sync.Mutex
}

var m sync.Mutex

func NewBountyHandler(httpClient HttpClient, database db.Database) *bountyHandler {
dbConf := db.NewDatabaseConfig(&gorm.DB{})
return &bountyHandler{
Expand Down Expand Up @@ -449,7 +448,7 @@ func (h *bountyHandler) GenerateBountyResponse(bounties []db.NewBounty) []db.Bou
}

func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request) {
m.Lock()
h.m.Lock()

ctx := r.Context()
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)
Expand Down Expand Up @@ -581,11 +580,11 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request
}
}

m.Unlock()
h.m.Unlock()
}

func (h *bountyHandler) BountyBudgetWithdraw(w http.ResponseWriter, r *http.Request) {
m.Lock()
h.m.Lock()

ctx := r.Context()
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)
Expand Down Expand Up @@ -647,12 +646,12 @@ func (h *bountyHandler) BountyBudgetWithdraw(w http.ResponseWriter, r *http.Requ
json.NewEncoder(w).Encode(errMsg)
}

m.Unlock()
h.m.Unlock()
}

// Todo: change back to NewBountyBudgetWithdraw
func (h *bountyHandler) NewBountyBudgetWithdraw(w http.ResponseWriter, r *http.Request) {
m.Lock()
h.m.Lock()

ctx := r.Context()
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)
Expand Down Expand Up @@ -711,7 +710,7 @@ func (h *bountyHandler) NewBountyBudgetWithdraw(w http.ResponseWriter, r *http.R
json.NewEncoder(w).Encode(errMsg)
}

m.Unlock()
h.m.Unlock()
}

func formatPayError(errorMsg string) db.InvoicePayError {
Expand Down

0 comments on commit e6e7deb

Please sign in to comment.