Skip to content

Commit

Permalink
refactor: Moving unlock to a defer
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Jul 20, 2022
1 parent 6430eb9 commit 70d88d6
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 8 deletions.
3 changes: 1 addition & 2 deletions pkg/share/amqp.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ func (a *App) AmqpHandler(message amqp.Delivery) error {
}

a.Lock()
defer a.Unlock()

if share.Creation.IsZero() {
delete(a.shares, share.ID)
} else {
a.shares[share.ID] = share
}

a.Unlock()

return nil
}
3 changes: 1 addition & 2 deletions pkg/share/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (a *App) generateID() (string, error) {
// List shares
func (a *App) List() (shares []provider.Share) {
a.RLock()
defer a.RUnlock()

var i int64
shares = make([]provider.Share, len(a.shares))
Expand All @@ -38,8 +39,6 @@ func (a *App) List() (shares []provider.Share) {
i++
}

a.RUnlock()

sort.Sort(provider.ShareByID(shares))

return shares
Expand Down
3 changes: 1 addition & 2 deletions pkg/webhook/amqp.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ func (a *App) AmqpHandler(message amqp.Delivery) error {
}

a.Lock()
defer a.Unlock()

if len(webhook.URL) == 0 {
delete(a.webhooks, webhook.ID)
} else {
a.webhooks[webhook.ID] = webhook
}

a.Unlock()

return nil
}
3 changes: 1 addition & 2 deletions pkg/webhook/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (a *App) generateID() (string, error) {
// List webhooks
func (a *App) List() (webhooks []provider.Webhook) {
a.RLock()
defer a.RUnlock()

var i int64
webhooks = make([]provider.Webhook, len(a.webhooks))
Expand All @@ -36,8 +37,6 @@ func (a *App) List() (webhooks []provider.Webhook) {
i++
}

a.RUnlock()

sort.Sort(provider.WebhookByID(webhooks))

return webhooks
Expand Down

0 comments on commit 70d88d6

Please sign in to comment.