23 lines
267 B
Go
23 lines
267 B
Go
package counter
|
|
|
|
import "sync"
|
|
|
|
type Counter struct {
|
|
count int
|
|
mutex sync.Mutex
|
|
}
|
|
|
|
func NewCounter() *Counter {
|
|
return &Counter{}
|
|
}
|
|
|
|
func (c *Counter) Inc() {
|
|
c.mutex.Lock()
|
|
defer c.mutex.Unlock()
|
|
c.count++
|
|
}
|
|
|
|
func (c *Counter) Value() int {
|
|
return c.count
|
|
}
|