go-by-test/counter/counter.go

23 lines
267 B
Go
Raw Normal View History

2024-09-21 15:51:58 +00:00
package counter
import "sync"
2024-09-21 15:51:58 +00:00
type Counter struct {
count int
mutex sync.Mutex
2024-09-21 15:51:58 +00:00
}
2024-09-21 17:48:58 +00:00
func NewCounter() *Counter {
return &Counter{}
}
2024-09-21 15:51:58 +00:00
func (c *Counter) Inc() {
c.mutex.Lock()
defer c.mutex.Unlock()
2024-09-21 15:51:58 +00:00
c.count++
}
func (c *Counter) Value() int {
return c.count
}