Documentation ¶
Index ¶
- func GetLocalIP() string
- func GoWithRecovery(exec func(), recoverFn func(r interface{}))
- func WithRetry(ctx context.Context, maxRetryTimes uint, duration time.Duration, ...)
- func WithRetryBackoff(ctx context.Context, maxRetryTimes uint, firstDuration time.Duration, ...)
- type BytesBufferPool
- type HeaderPool
- type RateLimit
- type ResponseWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetLocalIP ¶
func GetLocalIP() string
GetLocalIP will return a local IP(non-loopback, non 0.0.0.0), if there is one
func GoWithRecovery ¶
func GoWithRecovery(exec func(), recoverFn func(r interface{}))
GoWithRecovery wraps goroutine startup call with force recovery. it will dump current goroutine stack into log if catch any recover result.
exec: execute logic function. recoverFn: handler will be called after recover and before dump stack, passing `nil` means noop.
func WithRetry ¶
WithRetry provides a general retry logic.
The given f will keep running, until: - f returns true. It means work is done. - retry times is greater than the given times - ctx is done.
Otherwise, this function will wait a time of the given duration and continue to execute f.
The argument provided for f is the retried times.
func WithRetryBackoff ¶
func WithRetryBackoff(ctx context.Context, maxRetryTimes uint, firstDuration time.Duration, f func(uint) bool)
WithRetryBackoff provides a general retry logic.
The given f will keep running, until: - f returns true. It means work is done. - retry times is greater than the given times - ctx is done.
Otherwise, this function will wait a time of the given duration in a backoff way, and continue to execute f.
The argument provided for f is the retried times.
Types ¶
type BytesBufferPool ¶
type BytesBufferPool struct {
// contains filtered or unexported fields
}
func (*BytesBufferPool) Get ¶
func (bbp *BytesBufferPool) Get() *bytes.Buffer
func (*BytesBufferPool) Put ¶
func (bbp *BytesBufferPool) Put(bb *bytes.Buffer)
type HeaderPool ¶
type HeaderPool struct {
// contains filtered or unexported fields
}
func (*HeaderPool) Get ¶
func (hdp *HeaderPool) Get() http.Header
func (*HeaderPool) Put ¶
func (hdp *HeaderPool) Put(hdv http.Header)
type RateLimit ¶
type RateLimit struct {
// contains filtered or unexported fields
}
RateLimit wraps a fix sized channel to control concurrency.
func NewRateLimit ¶
NewRateLimit creates a limit controller with capacity n.
func (*RateLimit) GetCapacity ¶
GetCapacity returns the token capacity.
type ResponseWriter ¶
func NewRespWriter ¶
func NewRespWriter(body *bytes.Buffer, header http.Header) ResponseWriter
func (*ResponseWriter) Header ¶
func (r *ResponseWriter) Header() http.Header
func (*ResponseWriter) WriteHeader ¶
func (r *ResponseWriter) WriteHeader(statusCode int)