stats.go 599 B

123456789101112131415161718192021222324252627282930
  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. }
  21. func ManagerType() interface{} {
  22. return (*Manager)(nil)
  23. }