util

package
v0.0.0-...-ce66ebf Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2023 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InfiniteRetry = 0
)
View Source
const Pointer = reflect.Pointer

Variables

This section is empty.

Functions

func FNV32

func FNV32(s string) uint32

func FilterSimpleArgs

func FilterSimpleArgs(args []interface{}) (simpleArgs []interface{})

FilterSimpleArgs filters out the simple type arguments int, string, bool, and []byte

func GetEnvVarBool

func GetEnvVarBool(n string) (bool, bool)

func GetEnvVarDuration

func GetEnvVarDuration(n string) (time.Duration, bool)

func GetEnvVarInt

func GetEnvVarInt(n string) (int, bool)

func IsPaperTrade

func IsPaperTrade() bool

func MaskKey

func MaskKey(key string) string

func MillisecondsJitter

func MillisecondsJitter(d time.Duration, jitterInMilliseconds int) time.Duration

func NewValidLimiter

func NewValidLimiter(r rate.Limit, b int) (*rate.Limiter, error)

func Retry

func Retry(ctx context.Context, attempts int, duration time.Duration, fnToRetry func() error, errHandler func(error), predicators ...RetryPredicator) (err error)

Retry retrys the passed function for "attempts" times, if passed function return error. Setting attempts to zero means keep retrying.

func SafeMkdirAll

func SafeMkdirAll(p string) error

func SetEnvVarBool

func SetEnvVarBool(n string, v *bool) bool

func ShouldDelay

func ShouldDelay(l *rate.Limiter, minInterval time.Duration) time.Duration

func StringSliceContains

func StringSliceContains(slice []string, needle string) bool

func StringSplitByLength

func StringSplitByLength(s string, length int) (result []string)

func TryLock

func TryLock(lock *sync.RWMutex) bool

func TryRLock

func TryRLock(lock *sync.RWMutex) bool

func UnixMilli

func UnixMilli() int64

func WriteJsonFile

func WriteJsonFile(p string, obj interface{}) error

Types

type Reonce

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

func (*Reonce) Do

func (o *Reonce) Do(f func())

func (*Reonce) Reset

func (o *Reonce) Reset()

type Response

type Response struct {
	*http.Response

	// Body overrides the composited Body field.
	Body []byte
}

Response is wrapper for standard http.Response and provides more methods.

func NewResponse

func NewResponse(r *http.Response) (response *Response, err error)

NewResponse is a wrapper of the http.Response instance, it reads the response body and close the file.

func (*Response) DecodeJSON

func (r *Response) DecodeJSON(o interface{}) error

func (*Response) IsError

func (r *Response) IsError() bool

func (*Response) IsHTML

func (r *Response) IsHTML() bool

func (*Response) IsJSON

func (r *Response) IsJSON() bool

func (*Response) String

func (r *Response) String() string

String converts response body to string. An empty string will be returned if error.

type RetryPredicator

type RetryPredicator func(e error) bool

type TimeProfile

type TimeProfile struct {
	Name               string
	StartTime, EndTime time.Time
	Duration           time.Duration
}

func StartTimeProfile

func StartTimeProfile(args ...string) TimeProfile

func (*TimeProfile) Stop

func (p *TimeProfile) Stop() time.Duration

func (*TimeProfile) StopAndLog

func (p *TimeProfile) StopAndLog(f logFunction)

func (*TimeProfile) TilNow

func (p *TimeProfile) TilNow() time.Duration

type VolatileMemory

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

func NewDetectorCache

func NewDetectorCache() *VolatileMemory

func (*VolatileMemory) IsObjectFresh

func (i *VolatileMemory) IsObjectFresh(obj interface{}, ttl time.Duration) bool

func (*VolatileMemory) IsTextFresh

func (i *VolatileMemory) IsTextFresh(text string, ttl time.Duration) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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