代码拉取完成,页面将自动刷新
package utils
import (
"sync"
)
// Map exported
type Map struct {
sync.Map
mu sync.RWMutex
}
// Incr map
func (m *Map) Incr(key string, amount int) {
m.mu.Lock()
if count, ok := m.LoadOrStore(key, amount); ok {
m.Store(key, count.(int)+amount)
}
m.mu.Unlock()
}
// Counter exported
type Counter struct {
sync.RWMutex
Data map[string]int
}
// Get exported
func (c *Counter) Get(key string) int {
c.RLock()
count := c.Data[key]
c.RUnlock()
return count
}
// Set exported
func (c *Counter) Set(key string, value int) {
c.Lock()
c.Data[key] = value
c.Unlock()
}
// Incr exported
func (c *Counter) Incr(key string, amount int) int {
c.Lock()
c.Data[key] += amount
count := c.Data[key]
c.Unlock()
return count
}
// Delete exported
func (c *Counter) Delete(key string) {
c.Lock()
delete(c.Data, key)
c.Unlock()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。