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
1 changed files with 3 additions and 7 deletions
10
main.go
10
main.go
|
@ -82,12 +82,6 @@ func (r *RegionCounter) countRegion(region string) {
|
||||||
r.RegionCount[region] = val + 1
|
r.RegionCount[region] = val + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RegionCounter) getRegionCount() map[string]int {
|
|
||||||
r.RLock()
|
|
||||||
defer r.RUnlock()
|
|
||||||
return r.RegionCount
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
regionCounter := &RegionCounter{
|
regionCounter := &RegionCounter{
|
||||||
RegionCount: make(map[string]int),
|
RegionCount: make(map[string]int),
|
||||||
|
@ -167,7 +161,9 @@ func main() {
|
||||||
})
|
})
|
||||||
|
|
||||||
app.Get("/regions", func(c *fiber.Ctx) error {
|
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")
|
app.Listen(":8080")
|
||||||
|
|
Loading…
Add table
Reference in a new issue