stats.go 539 B

1234567891011121314151617181920212223242526
  1. package stats
  2. import "v2ray.com/core/features"
  3. type Counter interface {
  4. Value() int64
  5. Set(int64) int64
  6. Add(int64) int64
  7. }
  8. type Manager interface {
  9. features.Feature
  10. RegisterCounter(string) (Counter, error)
  11. GetCounter(string) Counter
  12. }
  13. // GetOrRegisterCounter tries to get the StatCounter first. If not exist, it then tries to create a new counter.
  14. func GetOrRegisterCounter(m Manager, name string) (Counter, error) {
  15. counter := m.GetCounter(name)
  16. if counter != nil {
  17. return counter, nil
  18. }
  19. return m.RegisterCounter(name)
  20. }