Documentation
¶
Overview ¶
Package util provides some utility tools for other components. Such as net-transporting, file-operating, rate-limiter.
Index ¶
- Constants
- Variables
- func AddConsoleLog(logger *log.Logger)
- func CreateLogger(logPath string, logName string, logLevel string, sign string) *log.Logger
- func IsEmptyStr(s string) bool
- func IsNil(value interface{}) (result bool)
- func Max(x, y int32) int32
- func Min(x, y int32) int32
- func PanicIfError(err error, msg string)
- func PanicIfNil(obj interface{}, msg string)
- type ConsoleHook
- type DragonflyFormatter
- type RateLimiter
- type StdPrinter
Constants ¶
const DefaultLogTimeFormat = "2006-01-02 15:04:05.000"
DefaultLogTimeFormat defines the timestamp format.
Variables ¶
var ( // Printer is global StdPrinter. Printer = &StdPrinter{Out: os.Stdout} )
Functions ¶
func AddConsoleLog ¶
AddConsoleLog will add a ConsoleLog into logger's hooks. It will output logs to console when logger's outputting logs.
func CreateLogger ¶
CreateLogger creates a logger.
func PanicIfError ¶
PanicIfError panic if an error happened.
Types ¶
type ConsoleHook ¶
type ConsoleHook struct {
// contains filtered or unexported fields
}
ConsoleHook shows logs on console.
func (*ConsoleHook) Fire ¶
func (ch *ConsoleHook) Fire(entry *log.Entry) error
Fire implements Hook#Fire.
func (*ConsoleHook) Levels ¶
func (ch *ConsoleHook) Levels() []log.Level
Levels implements Hook#Levels().
type DragonflyFormatter ¶
type DragonflyFormatter struct { // TimestampFormat sets the format used for marshaling timestamps. TimestampFormat string Sign string }
DragonflyFormatter customizes the dragonfly log format.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter is used for limiting the rate of transporting.
func NewRateLimiter ¶
func NewRateLimiter(rate int32, window int64) *RateLimiter
NewRateLimiter creates a RateLimiter instance. rate: how many tokens are generated per second. 0 represents that don't limit the rate. window: generating tokens interval (millisecond, [1,1000]). The production of rate and window should be division by 1000.
func (*RateLimiter) AcquireBlocking ¶
func (rl *RateLimiter) AcquireBlocking(token int32) int32
AcquireBlocking acquires tokens. It will be blocking unit the bucket has enough required number of tokens.
func (*RateLimiter) AcquireNonBlocking ¶
func (rl *RateLimiter) AcquireNonBlocking(token int32) int32
AcquireNonBlocking acquires tokens. It will return -1 immediately when there is no enough number of tokens.
func (*RateLimiter) SetRate ¶
func (rl *RateLimiter) SetRate(rate int32)
SetRate sets rate of RateLimiter.
type StdPrinter ¶
StdPrinter output info to console directly.
func (*StdPrinter) Printf ¶
func (sp *StdPrinter) Printf(format string, a ...interface{})
Printf formats according to a format specifier.
func (*StdPrinter) Println ¶
func (sp *StdPrinter) Println(msg string)
Println output info to console directly.