utils

package
v0.0.0-...-8c5e976 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: MIT Imports: 16 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 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 MixUpDisplay

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

mix up sensitive info to display

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 ReserveSlice

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

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 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
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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