id.go 211 B

123456789101112131415161718192021
  1. package jsonrpc2
  2. import (
  3. "sync"
  4. )
  5. var (
  6. idCounter int
  7. idMu sync.Mutex
  8. )
  9. func nextID() int {
  10. idMu.Lock()
  11. defer idMu.Unlock()
  12. idCounter++
  13. if idCounter < 0 {
  14. idCounter = 1
  15. }
  16. return idCounter
  17. }