Documentation
¶
Overview ¶
Package counters provides a simple counter, max and min functionalities. All counters are kept in CounterBox. Library is thread safe.
Index ¶
- func InitCountersOnSignal(logger TrivialLogger, box Counters)
- func LogCountersEvery(logger TrivialLogger, box Counters, d time.Duration)
- type Counter
- type CounterBox
- func (c *CounterBox) CreateHTTPHandler() http.HandlerFunc
- func (c *CounterBox) Get(name string) Counter
- func (c *CounterBox) GetCounter(name string) Counter
- func (c *CounterBox) GetMax(name string) MaxMinValue
- func (c *CounterBox) GetMin(name string) MaxMinValue
- func (c *CounterBox) Max(name string) MaxMinValue
- func (c *CounterBox) Min(name string) MaxMinValue
- func (c *CounterBox) Names() []string
- func (c *CounterBox) Prefix() string
- func (c *CounterBox) String() string
- func (c *CounterBox) WithPrefix(name string) Counters
- func (c *CounterBox) WriteTo(w io.Writer) (int64, error)
- type Counters
- type MaxMinValue
- type TrivialLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitCountersOnSignal ¶
func InitCountersOnSignal(logger TrivialLogger, box Counters)
InitCountersOnSignal impl
func LogCountersEvery ¶
func LogCountersEvery(logger TrivialLogger, box Counters, d time.Duration)
LogCountersEvery impl
Types ¶
type Counter ¶
type Counter interface {
// Increment increases counter by one.
Increment() int64
// IncrementBy increases counter by a given number.
IncrementBy(num int) int64
// Decrement decreases counter by one.
Decrement() int64
// DecrementBy decreases counter by a given number.
DecrementBy(num int) int64
// Set sets a specific value.
Set(num int)
// Name returns a name of counter.
Name() string
// Value returns a current value of counter.
Value() int64
}
Counter is an interface for integer increase only counter.
type CounterBox ¶
type CounterBox struct {
// contains filtered or unexported fields
}
CounterBox is a main type, it keeps references to all counters requested from it.
func NewCounterBox ¶
func NewCounterBox() *CounterBox
NewCounterBox creates a new object to keep all counters.
func (*CounterBox) CreateHTTPHandler ¶
func (c *CounterBox) CreateHTTPHandler() http.HandlerFunc
CreateHTTPHandler creates a simple handler printing values of all counters.
func (*CounterBox) GetCounter ¶
func (c *CounterBox) GetCounter(name string) Counter
GetCounter returns a counter of given name, if doesn't exist than create.
func (*CounterBox) GetMax ¶
func (c *CounterBox) GetMax(name string) MaxMinValue
GetMax returns a maxima counter of given name, if doesn't exist than create.
func (*CounterBox) GetMin ¶
func (c *CounterBox) GetMin(name string) MaxMinValue
GetMin returns a minima counter of given name, if doesn't exist than create.
func (*CounterBox) String ¶
func (c *CounterBox) String() string
func (*CounterBox) WithPrefix ¶
func (c *CounterBox) WithPrefix(name string) Counters
WithPrefix impl
type Counters ¶
type Counters interface {
Get(string) Counter
Min(string) MaxMinValue
Max(string) MaxMinValue
WithPrefix(string) Counters
GetCounter(string) Counter
GetMin(string) MaxMinValue
GetMax(string) MaxMinValue
WriteTo(w io.Writer) (int64, error)
Prefix() string
String() string
}
Counters interface
type MaxMinValue ¶
type MaxMinValue interface {
// Set allows to update value if necessary.
Set(int)
// Name returns a name of counter.
Name() string
// Value returns a current value.
Value() int64
}
MaxMinValue is an interface for minima and maxima counters.
type TrivialLogger ¶
type TrivialLogger interface {
Print(...interface{})
}
TrivialLogger logger interface