lock region map on read access
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
89a3cf0eab
commit
d8e96c78f8
10
main.go
10
main.go
|
@ -82,12 +82,6 @@ func (r *RegionCounter) countRegion(region string) {
|
|||
r.RegionCount[region] = val + 1
|
||||
}
|
||||
|
||||
func (r *RegionCounter) getRegionCount() map[string]int {
|
||||
r.RLock()
|
||||
defer r.RUnlock()
|
||||
return r.RegionCount
|
||||
}
|
||||
|
||||
func main() {
|
||||
regionCounter := &RegionCounter{
|
||||
RegionCount: make(map[string]int),
|
||||
|
@ -167,7 +161,9 @@ func main() {
|
|||
})
|
||||
|
||||
app.Get("/regions", func(c *fiber.Ctx) error {
|
||||
return c.JSON(regionCounter.getRegionCount())
|
||||
regionCounter.RLock()
|
||||
defer regionCounter.RUnlock()
|
||||
return c.JSON(regionCounter.RegionCount)
|
||||
})
|
||||
|
||||
app.Listen(":8080")
|
||||
|
|
Loading…
Reference in a new issue