lock region map on read access
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Garionion 2022-04-02 02:11:32 +02:00
parent 89a3cf0eab
commit d8e96c78f8

10
main.go
View file

@ -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")