utils

package
v0.0.0-...-4702bed Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

** description(""). ** copyright('tuoyun,www.tuoyun.net'). ** author("fg,Gordon@tuoyun.net"). ** time(2021/4/8 15:09).

** description(""). ** copyright('tuoyun,www.tuoyun.net'). ** author("fg,Gordon@tuoyun.net"). ** time(2021/2/22 11:52).

Index

Constants

View Source
const (
	BYTE = 1 << (10 * iota)
	KILOBYTE
	MEGABYTE
	GIGABYTE
	TERABYTE
	PETABYTE
	EXABYTE
)
View Source
const (
	TimeOffset = 8 * 3600  //8 hour offset
	HalfOffset = 12 * 3600 //Half-day hourly offset
)

Variables

View Source
var ServerIP = ""

Functions

func AesDecrypt

func AesDecrypt(data []byte, key []byte) ([]byte, error)

func AesEncrypt

func AesEncrypt(data []byte, key []byte) ([]byte, error)

func Base64Decode

func Base64Decode(data string) string

func Base64Encode

func Base64Encode(data string) string

func ByteSize

func ByteSize(bytes uint64) string

func CopyStructFields

func CopyStructFields(a interface{}, b interface{}, fields ...string) (err error)

copy a by b b->a

func CorsHandler

func CorsHandler() gin.HandlerFunc

func Difference

func Difference(slice1, slice2 []uint32) []uint32

Get the diff of two slices

func DifferenceString

func DifferenceString(slice1, slice2 []string) []string

Get the diff of two slices

func GenSmallImage

func GenSmallImage(src, dst string) error

func GetConversationIDBySessionType

func GetConversationIDBySessionType(sourceID string, sessionType int) string

func GetCurDayHalfTimeFormat

func GetCurDayHalfTimeFormat() string

Get the formatted time at 12 o'clock of the day, the format is "2006-01-02_12-00-00"

func GetCurDayHalfTimestamp

func GetCurDayHalfTimestamp() int64

Get the timestamp at 12 o'clock on the day

func GetCurDayZeroTimeFormat

func GetCurDayZeroTimeFormat() string

Get the formatted time at 0 o'clock of the day, the format is "2006-01-02_00-00-00"

func GetCurDayZeroTimestamp

func GetCurDayZeroTimestamp() int64

Get the timestamp at 0 o'clock of the day

func GetCurrentTimestampByMill

func GetCurrentTimestampByMill() int64

Get the current timestamp by Mill

func GetCurrentTimestampByNano

func GetCurrentTimestampByNano() int64

Get the current timestamp by Nano

func GetCurrentTimestampBySecond

func GetCurrentTimestampBySecond() int64

Get the current timestamp by Second

func GetLocalIP

func GetLocalIP() (string, error)

func GetMsgID

func GetMsgID(sendID string) string

func GetNewFileNameAndContentType

func GetNewFileNameAndContentType(fileName string, fileType int) (string, string)

func GetSelfFuncName

func GetSelfFuncName() string

func GetSwitchFromOptions

func GetSwitchFromOptions(Options map[string]bool, key string) (result bool)

func GetTimeStampByFormat

func GetTimeStampByFormat(datetime string) string

func Int32ToString

func Int32ToString(i int32) string

func Int64ToString

func Int64ToString(i int64) string

func IntToString

func IntToString(i int) string

func InterfaceArrayToStringArray

func InterfaceArrayToStringArray(data []interface{}) (i []string)

func Intersect

func Intersect(slice1, slice2 []uint32) []uint32

Get the intersection of two slices

func IntersectString

func IntersectString(slice1, slice2 []string) []string

Get the intersection of two slices

func IsContain

func IsContain(target string, List []string) bool

judge a string whether in the string list

func IsContainInt

func IsContainInt(target int, List []int) bool

func IsContainInt32

func IsContainInt32(target int32, List []int32) bool

func IsDir

func IsDir(path string) bool

Determine whether the given path is a folder

func IsFile

func IsFile(path string) bool

Determine whether the given path is a file

func JsonStringToMap

func JsonStringToMap(str string) (tempMap map[string]int32)

func JsonStringToStruct

func JsonStringToStruct(s string, args interface{}) error

The incoming parameter must be a pointer

func Map2Pb

func Map2Pb(m map[string]string) (pb proto.Message, err error)

func MapIntToJsonString

func MapIntToJsonString(param map[string]int32) string

func MapToJsonString

func MapToJsonString(param map[string]interface{}) string

func Md5

func Md5(s string, salt ...string) string

func MkDir

func MkDir(path string) error

Create a directory

func OperationIDGenerator

func OperationIDGenerator() string

func Pb2Map

func Pb2Map(pb proto.Message) (map[string]interface{}, error)

func Pb2String

func Pb2String(pb proto.Message) (string, error)

func RemoveDuplicateElement

func RemoveDuplicateElement(idList []string) []string

func RemoveFromSlice

func RemoveFromSlice(slice1, slice2 []string) []string

func RemoveRepeatedStringInList

func RemoveRepeatedStringInList(slc []string) []string

func SetSwitchFromOptions

func SetSwitchFromOptions(options map[string]bool, key string, value bool)

func String2Pb

func String2Pb(s string, pb proto.Message) error

func StringToInt

func StringToInt(i string) int

func StringToInt32

func StringToInt32(i string) int32

func StringToInt64

func StringToInt64(i string) int64

func StructToJsonBytes

func StructToJsonBytes(param interface{}) []byte

func StructToJsonString

func StructToJsonString(param interface{}) string

func TimeStringFormatTimeUnix

func TimeStringFormatTimeUnix(timeFormat string, timeSrc string) int64

func TimeStringToTime

func TimeStringToTime(timeString string) (time.Time, error)

func TimeToString

func TimeToString(t time.Time) string

func Uint32ToString

func Uint32ToString(i uint32) string

func UnixMillSecondToTime

func UnixMillSecondToTime(millSecond int64) time.Time

func UnixNanoSecondToTime

func UnixNanoSecondToTime(nanoSecond int64) time.Time

Convert nano timestamp to time.Time type

func UnixSecondToTime

func UnixSecondToTime(second int64) time.Time

Convert timestamp to time.Time type

func WithMessage

func WithMessage(err error, message string) error

func Wrap

func Wrap(err error, message string) error

Types

type Map

type Map struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Map) Del

func (m *Map) Del(key interface{})

func (*Map) Get

func (m *Map) Get(key interface{}) interface{}

func (*Map) Len

func (m *Map) Len() int

func (*Map) LockRange

func (m *Map) LockRange(f func(interface{}, interface{}))

func (*Map) RLockRange

func (m *Map) RLockRange(f func(interface{}, interface{}))

func (*Map) Set

func (m *Map) Set(key interface{}, value interface{})

func (*Map) TestAndSet

func (m *Map) TestAndSet(key interface{}, value interface{}) interface{}

func (*Map) UnsafeDel

func (m *Map) UnsafeDel(key interface{})

func (*Map) UnsafeGet

func (m *Map) UnsafeGet(key interface{}) interface{}

func (*Map) UnsafeLen

func (m *Map) UnsafeLen() int

func (*Map) UnsafeRange

func (m *Map) UnsafeRange(f func(interface{}, interface{}))

func (*Map) UnsafeSet

func (m *Map) UnsafeSet(key interface{}, value interface{})

Jump to

Keyboard shortcuts

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