utils

package
v0.0.0-...-29e355a Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const Day = 24 * time.Hour

Variables

This section is empty.

Functions

func ConvertIntSlice

func ConvertIntSlice[U, T Int](in []T) (out []U)

func DayRange

func DayRange(t time.Time) (time.Time, time.Time)

DayRange returns the start and end of the day of the given time.

func DigestDisplay

func DigestDisplay(data interface{}) string

简单摘要, 用于debug对比敏感信息

func Display

func Display(data interface{}) string

display object info, the struct will be convert to json, %+v as the final method, basic type will be use %+v too

func GetNonEmptyStr

func GetNonEmptyStr(s ...string) string

func IPInCIDR

func IPInCIDR(ipStr, cidrStr string) bool

func InLocWithSameLiteralTime

func InLocWithSameLiteralTime(t time.Time, loc *time.Location) time.Time

InLocWithSameLiteralTime returns a time with the same literal time in the given location. For example, if t is 2019-01-01 00:00:00 +0800 CST, and loc is UTC, then the returned time will be 2019-01-01 00:00:00 +0000 UTC.

func InLocWithSameTrueTime

func InLocWithSameTrueTime(t time.Time, loc *time.Location) time.Time

InLocWithSameTrueTime returns a time with the same true time in the given location. For example, if t is 2019-01-01 00:00:00 +0800 CST, and loc is UTC, then the returned time will be 2019-01-01 08:00:00 +0000 UTC.

func InSlice

func InSlice[T comparable](slice []T, s T) bool

func IsBlankStr

func IsBlankStr(s string) bool

func IsBlankStrPtr

func IsBlankStrPtr(s *string) bool

func IsDigits

func IsDigits(s string) bool

func JsonDeepCopy

func JsonDeepCopy[T any](v T) *T

func Marshal

func Marshal(v interface{}) ([]byte, error)

func MixUpDisplay

func MixUpDisplay(data interface{}, probability float32) string

mix up sensitive info to display

func MustJsonDecodeString

func MustJsonDecodeString(v string, out interface{})

func MustJsonEncodeBytes

func MustJsonEncodeBytes(v interface{}) []byte

func MustJsonEncodeString

func MustJsonEncodeString(v interface{}) string

func Prepend

func Prepend[T any](slice []T, e T) []T

NOTE:non gurantee for order

func ProtectPanic

func ProtectPanic(ctx context.Context, execFunc func() error) (err error)

func Ref

func Ref[T any](v T) *T

func ReserveSlice

func ReserveSlice[T any](slice []T, capacity int) []T

func Retry

func Retry(ctx context.Context, execFunc func(ctx context.Context) error, options ...RetryOption) error

func RetryMaxTimes

func RetryMaxTimes(maxTimes int, interval time.Duration) func(*RetryParams)

func RetryMaxTimout

func RetryMaxTimout(retryMaxTimout, interval time.Duration) func(*RetryParams)

func SplitSlice

func SplitSlice[T any](slice []T, n int) (ret [][]T)

func StringMapEqual

func StringMapEqual(lhs, rhs map[string]string) bool

func TruncateDay

func TruncateDay(t time.Time) time.Time

TruncateDay returns the start of the day of the given time.

func TruncateWeek

func TruncateWeek(t time.Time) time.Time

TruncateWeek returns the start of the week of the given time.

func Unique

func Unique[T comparable](slice []T) []T

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

func ValueFromRef

func ValueFromRef[T any](v *T) T

func WeekRange

func WeekRange(t time.Time) (time.Time, time.Time)

WeekRange returns the start and end of the week of the given time.

Types

type CIDRChecker

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

func NewCIDRChecker

func NewCIDRChecker(cidrStr string) *CIDRChecker

func (*CIDRChecker) Check

func (self *CIDRChecker) Check(ipStr string) bool

func (*CIDRChecker) String

func (self *CIDRChecker) String() string

type Int

type Int interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type RetryOption

type RetryOption func(*RetryParams)

type RetryParams

type RetryParams struct {
	RetryFailedInterval time.Duration
	MaxTimout           time.Duration
	MaxTimes            int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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