utils

package
v1.0.15 Latest Latest
Warning

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

Go to latest
Published: May 21, 2022 License: Apache-2.0, Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LettersAlphaNumber = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	LettersNumber      = "0123456789"
	LettersAlpha       = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
)

Variables

View Source
var BindSliceSep = ","

BindSliceSep the separator for parsing slice field

Functions

func Abs

func Abs(v int64) int64

Abs return the absolute value

func Bind

func Bind(ptr interface{}, tag string, input map[string]interface{}) error

Bind bind values to struct ptr

func Bytes2Str

func Bytes2Str(b []byte) string

Bytes2Str convert []byte to string without copy

func CRC32

func CRC32(data string) uint32

CRC32 return the CRC32 hash of string

func CountLine

func CountLine(fileName string) (int, error)

func FNV32a

func FNV32a(data string) uint32

FNV32a return the FNV32a hash of string

func FastUUID

func FastUUID() [24]byte

FastUUID generate a new UUID as []byte

func FastUUIDStr

func FastUUIDStr() string

FastUUIDStr generate a new UUID as string

func FillStruct

func FillStruct(ptr interface{}, data map[string]interface{})

FillStruct set the field value of ptr according data kv map.

func FillStructByTag

func FillStructByTag(ptr interface{}, tag string, input map[string]interface{}) (filled []string, err error)

FillStructByTag set the field value of struct s according

func Filter

func Filter(params map[string]interface{}, filters []string)

Filter filter out keys in params

func GetBool

func GetBool(v interface{}) bool

GetBool convert interface to bool.

func GetByKind

func GetByKind(kind reflect.Kind, v interface{}) (result interface{})

GetByKind convert interface to kind

func GetByteArray

func GetByteArray(v interface{}) []byte

GetByteArray convert interface to byte slice.

func GetDayRangeOfMonth

func GetDayRangeOfMonth(date time.Time) (firstDay, lastDay time.Time)

GetDayRangeOfMonth [firstDay, lastDay]

func GetExternalIP

func GetExternalIP() string

GetExternalIP return the first available external ip address

func GetFloat32

func GetFloat32(v interface{}) float32

GetFloat32 convert interface to float32.

func GetFloat64

func GetFloat64(v interface{}) float64

GetFloat64 convert interface to float64.

func GetInt

func GetInt(v interface{}) int

GetInt convert interface to int.

func GetInt16

func GetInt16(v interface{}) int16

GetInt16 convert interface to int16.

func GetInt32

func GetInt32(v interface{}) int32

GetInt32 convert interface to int32.

func GetInt64

func GetInt64(v interface{}) int64

GetInt64 convert interface to int64.

func GetInt64Slices

func GetInt64Slices(v interface{}) []int64

GetInt64Slices convert interface to []int64

func GetInt8

func GetInt8(v interface{}) int8

GetInt8 convert interface to int8.

func GetIntSlices

func GetIntSlices(v interface{}) []int

GetIntSlices convert interface to []int

func GetMonthsOfDayRange

func GetMonthsOfDayRange(layout string, beginDay, endDay time.Time) []string

GetMonthsOfDayRange return the month string of day range [beginDay, endDay]

func GetPanicStack

func GetPanicStack() string

GetPanicStack return the panic stack trace as string

func GetStack

func GetStack(calldepth int) []byte

GetStack return the stack trace of depth as []byte

func GetString

func GetString(v interface{}) string

GetString convert interface to string.

func GetTimeRangeOfDay

func GetTimeRangeOfDay(t time.Time) (begin, end time.Time)

GetTimeRangeOfDay [begin, end)

func GetUint

func GetUint(v interface{}) uint

GetUint convert interface to uint.

func GetUint16

func GetUint16(v interface{}) uint16

GetUint16 convert interface to uint16.

func GetUint32

func GetUint32(v interface{}) uint32

GetUint32 convert interface to uint32.

func GetUint64

func GetUint64(v interface{}) uint64

GetUint64 convert interface to uint64.

func GetUint64Slices

func GetUint64Slices(v interface{}) []uint64

GetUint64Slices convert interface to []uint64

func GetUint8

func GetUint8(v interface{}) uint8

GetUint8 convert interface to uint8.

func IsEmptyValue

func IsEmptyValue(v reflect.Value) bool

IsEmptyValue return true if the value is zero value

func IsErrClosing

func IsErrClosing(err error) bool

IsErrClosing return true if err indicates socket is closing

func IsFileExists

func IsFileExists(fileName string) (exists bool, err error)

func IsType

func IsType(value reflect.Value, expected reflect.Type) bool

IsType check type

func JoinSlice

func JoinSlice(slice interface{}, sep string) string

JoinSlice join the slice to string with separator `sep`

func LocatePanic

func LocatePanic() string

LocatePanic return the panic location

func Max

func Max[T constraints.Ordered](v ...T) T

Max return the maximum value

func Milliseconds

func Milliseconds(t time.Time) int64

Milliseconds return the milliseconds of time

func Min

func Min[T constraints.Ordered](v ...T) T

Min return the minimum value

func ParseJSON

func ParseJSON(data []byte, ptr interface{}) error

ParseJSON parse json with dynamic field parse support

func Rand

func Rand(min, max int) int

Rand return an random number between [min, max)

func RandString

func RandString(n int, letterBytes string) string

RandString return a random string of length n

func RepeatWithSep

func RepeatWithSep(s string, sep string, count int) string

RepeatWithSep repeat the `s` `count` times, and separated by `sep`

func SetDefaults

func SetDefaults(ptr interface{}) error

SetDefaults set the default value by tag `default:"value"`

func Split

func Split(str string, sep string) (r []string)

Split split the string. if empty return an empty slice instead of nil

func Str2Bytes

func Str2Bytes(s string) []byte

Str2Bytes convert string to []byte without copy

func StringJoin

func StringJoin(params ...interface{}) string

StringJoin join slice to single string

func StringsToInterfaces

func StringsToInterfaces(keys []string) []interface{}

StringsToInterfaces convert to []string to []interface{}

func TimeInUTCOffset

func TimeInUTCOffset(t time.Time, utcOffset int) time.Time

TimeInUTCOffset return time in specified utc offset

func TimeLocationOfUTCOffset

func TimeLocationOfUTCOffset(utcOffset int) *time.Location

TimeLocationOfUTCOffset return the time.Location of utc offset

func ToCamel

func ToCamel(s string) string

ToCamel returns a string converted from snake case to uppercase

func ToCamelLower

func ToCamelLower(s string) string

ToCamelLower returns a string converted from snake case to lowercase

func ToJSON

func ToJSON(v interface{}) string

ToJSON return json encoded string of interface.

func ToSnake

func ToSnake(s string) string

ToSnake converts a given string to snake case

func TouchFile

func TouchFile(fileName string) error

func TrimUntil

func TrimUntil(s string, stop string) string

TrimUntil trim the prefix until find the stop character

Types

type BindUnmarshaler

type BindUnmarshaler interface {
	UnmarshalBind(value string) error
}

BindUnmarshaler the bind unmarshal interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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