stats.go 694 B

12345678910111213141516171819202122232425262728293031
  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. // ManagerType returns the type of Manager interface. Can be used to implement common.HasType.
  22. func ManagerType() interface{} {
  23. return (*Manager)(nil)
  24. }