util

package
v1.61.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: AGPL-3.0 Imports: 16 Imported by: 36

Documentation

Index

Constants

View Source
const Pointer = reflect.Pointer

Variables

This section is empty.

Functions

func FNV32 added in v1.33.0

func FNV32(s string) uint32

func FilterSimpleArgs added in v1.33.4

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

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

func IsPaperTrade added in v1.33.0

func IsPaperTrade() bool

func LogErr added in v1.59.0

func LogErr(err error, msgAndArgs ...interface{}) bool

LogErr logs the error with the message and arguments if the error is not nil. It returns true if the error is not nil. Examples: LogErr(err) LogErr(err, "error message") LogErr(err, "error message %s", "with argument")

func MaskKey added in v1.21.0

func MaskKey(key string) string

func NewValidLimiter

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

func ParseRateLimitSyntax added in v1.60.1

func ParseRateLimitSyntax(desc string) (*rate.Limiter, error)

ParseRateLimitSyntax parses the rate limit syntax into the rate.Limiter parameters sample inputs:

	 2+1/5s (2 initial tokens, 1 token per 5 seconds)
	 5+3/1m (5 initial tokens, 3 tokens per minute)
     3m (3 tokens per minute)
     1/3m (1 token per 3 minutes)

func ReadJsonFile added in v1.51.0

func ReadJsonFile(file string, obj interface{}) error

func SafeMkdirAll added in v1.33.0

func SafeMkdirAll(p string) error

func ShouldDelay

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

func StringSliceContains added in v1.11.1

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

func StringSplitByLength added in v1.42.0

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

func TryLock added in v1.38.0

func TryLock(lock *sync.RWMutex) bool

func TryRLock added in v1.38.0

func TryRLock(lock *sync.RWMutex) bool

func UnixMilli added in v1.21.0

func UnixMilli() int64

func WriteJsonFile added in v1.33.0

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

Types

type Reonce added in v1.21.0

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

func (*Reonce) Do added in v1.21.0

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

func (*Reonce) Reset added in v1.21.0

func (o *Reonce) Reset()

type Response added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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

func (*Response) IsError added in v1.11.0

func (r *Response) IsError() bool

func (*Response) IsHTML added in v1.11.0

func (r *Response) IsHTML() bool

func (*Response) IsJSON added in v1.11.0

func (r *Response) IsJSON() bool

func (*Response) String added in v1.11.0

func (r *Response) String() string

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

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