stats

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package stats implements Stats that collects data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EntryDesc

type EntryDesc struct {
	// ID is unique in a Stats instance, or Register() will reject.
	ID int
	// Name will be part of the variable name.
	Name string
}

EntryDesc defines a pair of ID and Name for a stat field.

type Stats

type Stats struct {
	// contains filtered or unexported fields
}

Stats is a map of stats for the object.

func New

func New(_ string, stats ...EntryDesc) (*Stats, error)

New returns a new Stats.

func (*Stats) Add

func (s *Stats) Add(id int, delta int64) error

Add adds the given delta to the stat.

func (*Stats) Get

func (s *Stats) Get(id int) (int64, error)

Get reads the value of the given stat atomically. Non-existing ID will return an error.

func (*Stats) GetAll

func (s *Stats) GetAll() map[int]int64

GetAll returns all stats as a map of stat values, indexed by id.

func (*Stats) GetStatName

func (s *Stats) GetStatName(id int) (string, error)

GetStatName returns the string name of the stat ID. Non-existing ID will return an error.

func (*Stats) Update

func (s *Stats) Update(id int, value int64) error

Update updates the stat with the value provided.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL