You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stats.go 953B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package irc
  2. import (
  3. "sync"
  4. )
  5. // Stats contains the numbers of total, invisible and operators on the server
  6. type Stats struct {
  7. sync.RWMutex
  8. Total int
  9. Invisible int
  10. Operators int
  11. }
  12. // NewStats creates a new instance of Stats
  13. func NewStats() *Stats {
  14. serverStats := &Stats{
  15. Total: 0,
  16. Invisible: 0,
  17. Operators: 0,
  18. }
  19. return serverStats
  20. }
  21. // ChangeTotal increments the total user count on server
  22. func (s *Stats) ChangeTotal(i int) {
  23. s.Lock()
  24. defer s.Unlock()
  25. s.Total += i
  26. }
  27. // ChangeInvisible increments the invisible count
  28. func (s *Stats) ChangeInvisible(i int) {
  29. s.Lock()
  30. defer s.Unlock()
  31. s.Invisible += i
  32. }
  33. // ChangeOperators increases the operator count
  34. func (s *Stats) ChangeOperators(i int) {
  35. s.Lock()
  36. defer s.Unlock()
  37. s.Operators += i
  38. }
  39. // GetStats retrives total, invisible and oper count
  40. func (s *Stats) GetStats() (int, int, int) {
  41. s.Lock()
  42. defer s.Unlock()
  43. return s.Total, s.Invisible, s.Operators
  44. }