Documentation
¶
Index ¶
- Constants
- Variables
- func B2s(b []byte) string
- func BackupAndCleanDir(dir string) error
- func Exit(code int, msg string)
- func ExpandDir(dir string) string
- func GraphiteSplit(s string, lensep string, sep string) []string
- func IsDirEmpty(name string) bool
- func MkdirAll(path string) error
- func NextNumberPowerOf2(v uint64) uint64
- func NormalizeZapLogPath(path string) string
- func NotifySignal(c chan<- Signal, sig ...Signal) error
- func Now() time.Time
- func NowUnixNano() int64
- func PanicToErr(f func(), err *error) (failed bool)
- func RaiseSignal(pid int, sig Signal) error
- func RemoveAll(path string) error
- func RemoveRepeatedByte(s string, needRemoveByte byte) string
- func S2b(s string) []byte
- func ScanTokens(str string, removeEscapeChar bool, visitor TokenVisitor) (string, error)
- func Since(t time.Time) time.Duration
- func SysProcAttr() *syscall.SysProcAttr
- func UUID() (string, error)
- func ValidateName(name string) error
- type ExpDecaySample
- func (s *ExpDecaySample) Close()
- func (s *ExpDecaySample) Count() int64
- func (s *ExpDecaySample) Max() int64
- func (s *ExpDecaySample) Min() int64
- func (s *ExpDecaySample) Percentile(q float64) float64
- func (s *ExpDecaySample) StdDev() float64
- func (s *ExpDecaySample) Sum() int64
- func (s *ExpDecaySample) Update(v int64)
- func (s *ExpDecaySample) Variance() float64
- type Lazybuf
- type NamedCallback
- type NamedCallbackSet
- type NumericAvgAggregator
- type NumericMaxAggregator
- type NumericMinAggregator
- type NumericSumAggregator
- type Signal
- type StatAggregator
- type TokenVisitor
Constants ¶
const ( // CallbacksInitCapacity is the capacity of callback functions. CallbacksInitCapacity = 20 // NormalPriorityCallback is the name of normal priority callback. NormalPriorityCallback = "__NoRmAl_PrIoRiTy_CaLlBaCk" // CriticalPriorityCallback is the name of critical priority callback. CriticalPriorityCallback = "__CrItIcAl_PrIoRiTy_CaLlBaCk" )
const TokenEscapeChar string = `\`
TokenEscapeChar is the escape char
Variables ¶
var ( // TrueStrings contains all string represents true TrueStrings = []string{"1", "t", "true", "on", "y", "yes"} // FalseStrings contains all string represents false FalseStrings = []string{"0", "f", "false", "off", "n", "no"} )
var URLFriendlyCharactersRegex = regexp.MustCompile(`^[A-Za-z0-9\-_\.~]{1,253}$`)
URLFriendlyCharactersRegex - safe characters for friendly url, rfc3986 section 2.3
Functions ¶
func B2s ¶
B2s converts byte slice to a string without memory allocation. See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
Note it may break if string and/or slice header will change in the future go versions.
func BackupAndCleanDir ¶
BackupAndCleanDir cleans old stuff in both dir and backupDir, and backups dir to backupDir. The backupDir generated by appending postfix `_bak` for dir. It does nothing if dir does not exist.
func ExpandDir ¶
ExpandDir cleans the dir, and returns itself if it's absolute, otherwise prefix with the current/working directory.
func GraphiteSplit ¶
GraphiteSplit slices s into all substrings separated by sep returns a slice of the substrings without length prefix separated by lensep. The routine does its best to split without error returned.
func IsDirEmpty ¶
IsDirEmpty returns true if a directory is empty.
func NextNumberPowerOf2 ¶
NextNumberPowerOf2 return the number of power of 2 Via: https://stackoverflow.com/a/466242/1705845
https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
func NormalizeZapLogPath ¶ added in v1.2.0
NormalizeZapLogPath is a workaround for https://github.com/uber-go/zap/issues/621 the workaround is from https://github.com/ipfs/go-log/issues/73
func NotifySignal ¶ added in v1.2.0
NotifySignal is identical to os/signal.Notify on Linux param is mapped to abstract Signal and nil is not allowed
func PanicToErr ¶
PanicToErr try to recover panic and returns if it happened or not.
func RaiseSignal ¶ added in v1.2.0
RaiseSignal is identical to syscall.Kill on Linux param is mapped to abstract Signal
any chan passed to NotifySignal will receive the sig
func RemoveRepeatedByte ¶
RemoveRepeatedByte removes the repeated bytes.
func S2b ¶
S2b converts string to a byte slice without memory allocation.
Note it may break if string and/or slice header will change in the future go versions.
func ScanTokens ¶
func ScanTokens(str string, removeEscapeChar bool, visitor TokenVisitor) (string, error)
ScanTokens scans tokens.
func SysProcAttr ¶
func SysProcAttr() *syscall.SysProcAttr
SysProcAttr returns system process attribute
Types ¶
type ExpDecaySample ¶
type ExpDecaySample struct {
// contains filtered or unexported fields
}
ExpDecaySample is the structure use for monitoring metrics(such as: P90, P50 etc)
func NewExpDecaySample ¶
func NewExpDecaySample(timeRange time.Duration, secondsForEachBucket int) *ExpDecaySample
NewExpDecaySample creates ExpDecaySample structure
func (*ExpDecaySample) Percentile ¶
func (s *ExpDecaySample) Percentile(q float64) float64
Percentile calculates the percentile
func (*ExpDecaySample) StdDev ¶
func (s *ExpDecaySample) StdDev() float64
StdDev return the standard deviation value
func (*ExpDecaySample) Update ¶
func (s *ExpDecaySample) Update(v int64)
Update updates the ExpDecaySample
func (*ExpDecaySample) Variance ¶
func (s *ExpDecaySample) Variance() float64
Variance returns the variance value
type Lazybuf ¶
type Lazybuf struct {
// contains filtered or unexported fields
}
A Lazybuf is a lazily constructed path buffer. It supports append, reading previously appended bytes, and retrieving the final string. It does not allocate a buffer to hold the output until that output diverges from s.
type NamedCallback ¶
type NamedCallback struct {
// contains filtered or unexported fields
}
NamedCallback is the named callback struct
func NewNamedCallback ¶
func NewNamedCallback(name string, callback interface{}) *NamedCallback
NewNamedCallback returns a new named callback.
func (*NamedCallback) Callback ¶
func (cb *NamedCallback) Callback() interface{}
Callback returns callback function
func (*NamedCallback) SetCallback ¶
func (cb *NamedCallback) SetCallback(callback interface{}) interface{}
SetCallback sets the callback function
type NamedCallbackSet ¶
type NamedCallbackSet struct {
// contains filtered or unexported fields
}
NamedCallbackSet is a set of NamedCallback
func AddCallback ¶
func AddCallback(cbs *NamedCallbackSet, name string, callback interface{}, priority string) *NamedCallbackSet
AddCallback adds a callback into a callback set with priority
func DeleteCallback ¶
func DeleteCallback(cbs *NamedCallbackSet, name string) *NamedCallbackSet
DeleteCallback deletes a callback in callback set
func NewNamedCallbackSet ¶
func NewNamedCallbackSet() *NamedCallbackSet
NewNamedCallbackSet returns a new NamedCallbackSet
func (*NamedCallbackSet) CopyCallbacks ¶
func (cbs *NamedCallbackSet) CopyCallbacks() []*NamedCallback
CopyCallbacks copies the current callbacks
func (*NamedCallbackSet) GetCallbacks ¶
func (cbs *NamedCallbackSet) GetCallbacks() []*NamedCallback
GetCallbacks get callbacks
type NumericAvgAggregator ¶
type NumericAvgAggregator struct {
NumericSumAggregator
// contains filtered or unexported fields
}
NumericAvgAggregator is the structure with average value
func (*NumericAvgAggregator) Aggregate ¶
func (a *NumericAvgAggregator) Aggregate(num interface{}) error
Aggregate records the number of values and the sum of values
func (*NumericAvgAggregator) Result ¶
func (a *NumericAvgAggregator) Result() interface{}
Result returns the average values
func (*NumericAvgAggregator) String ¶
func (a *NumericAvgAggregator) String() string
String returns the name.
type NumericMaxAggregator ¶
type NumericMaxAggregator struct {
// contains filtered or unexported fields
}
NumericMaxAggregator is the structure with max value
func (*NumericMaxAggregator) Aggregate ¶
func (a *NumericMaxAggregator) Aggregate(num interface{}) error
Aggregate records the max of value
func (*NumericMaxAggregator) Result ¶
func (a *NumericMaxAggregator) Result() interface{}
Result return the max value
func (*NumericMaxAggregator) String ¶
func (a *NumericMaxAggregator) String() string
String returns the name.
type NumericMinAggregator ¶
type NumericMinAggregator struct {
// contains filtered or unexported fields
}
NumericMinAggregator is the structure with min value
func (*NumericMinAggregator) Aggregate ¶
func (a *NumericMinAggregator) Aggregate(num interface{}) error
Aggregate records the min value
func (*NumericMinAggregator) Result ¶
func (a *NumericMinAggregator) Result() interface{}
Result returns the min value.
func (*NumericMinAggregator) String ¶
func (a *NumericMinAggregator) String() string
String returns the name.
type NumericSumAggregator ¶
type NumericSumAggregator struct {
// contains filtered or unexported fields
}
NumericSumAggregator is the structure with sum value
func (*NumericSumAggregator) Aggregate ¶
func (a *NumericSumAggregator) Aggregate(num interface{}) error
Aggregate records the sum value
func (*NumericSumAggregator) Result ¶
func (a *NumericSumAggregator) Result() interface{}
Result returns the sum value.
func (*NumericSumAggregator) String ¶
func (a *NumericSumAggregator) String() string
String returns the name.
type Signal ¶ added in v1.2.0
type Signal string
Signal is cross platform abstract type of os.Signal
type StatAggregator ¶
StatAggregator is the interface