utils

package
v0.0.0-...-7a3883e Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2022 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SizeGB   = 1024 * 1024 * 1024
	SizeMB   = 1024 * 1024
	SizeKB   = 1024
	DecadeKB = 10240
)

Constants

View Source
const (
	CharactorsBase = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
)

Constants

Variables

This section is empty.

Functions

func CamelCaseSlices

func CamelCaseSlices(s string) []string

CamelCaseSlices splits XxYy into ["Xx", "Yy"]

func CamelCaseString

func CamelCaseString(s string) string

CamelCaseString converts xx_yy to xxYY

func ConvertObjectToMapData

func ConvertObjectToMapData(v interface{}, tag string) map[string]interface{}

ConvertObjectToMapData converter

func CopyMapperDataToObject

func CopyMapperDataToObject(src map[string]interface{}, dst interface{})

CopyMapperDataToObject copy data

func CopyObjectSimply

func CopyObjectSimply(src interface{}, dst interface{}, skipEmpty bool)

CopyObjectSimply copy object

func CurrentMillisecond

func CurrentMillisecond() int64

CurrentMillisecond millisecond

func DeeplyCopyObject

func DeeplyCopyObject(src interface{}, dst interface{}) error

DeeplyCopyObject deeply copy src object to dst object

func EnsureDirectory

func EnsureDirectory(path string) error

EnsureDirectory check the directory exists and create it if not exists

func FormDataCopyFields

func FormDataCopyFields(formData interface{}, dest interface{}, tagName string) int

FormDataCopyFields copy form data fields into db model fields

func GB18030ToUtf8

func GB18030ToUtf8(s []byte) ([]byte, error)

GB18030ToUtf8 converts gbk encoding text into utf-8

func GB2312ToUtf8

func GB2312ToUtf8(s []byte) ([]byte, error)

GB2312ToUtf8 converts gbk encoding text into utf-8

func GbkToUtf8

func GbkToUtf8(s []byte) ([]byte, error)

GbkToUtf8 converts gbk encoding text into utf-8

func GenLoweruuid

func GenLoweruuid() string

GenLoweruuid generate uuid with lower characters

func GenUUID

func GenUUID() string

GenUUID generate uuid with upper characters

func GetDigistIndex

func GetDigistIndex(digists string, c byte) int

GetDigistIndex get digist index

func GetLastPartString

func GetLastPartString(text string) string

GetLastPartString get last slice of the text

func GetRemoteAddress

func GetRemoteAddress(r *http.Request) string

GetRemoteAddress get http request remote ip

func GetSOAPAction

func GetSOAPAction(r *http.Request) string

GetSOAPAction get soap action

func HashCode

func HashCode(content []byte) uint32

HashCode hashes a buffer to a unique hashcode

func HashCodeAsInt

func HashCodeAsInt(content []byte) int

HashCodeAsInt hashes a buffer to a unique hashcode

func HumanByteSize

func HumanByteSize(bs int) string

HumanByteSize convert byte size as human recognizable

func HumanByteText

func HumanByteText(bs []byte) string

HumanByteText convert byte data as human readable text, not like %q contains quatations

func HumanToTimestamp

func HumanToTimestamp(format string, v string) int64

HumanToTimestamp converter

func IncreaseValueCustomizedDigist

func IncreaseValueCustomizedDigist(val string, digists string) string

IncreaseValueCustomizedDigist increase

func IsCapital

func IsCapital(s string) bool

IsCapital if strings has a capital character

func IsEmpty

func IsEmpty(val interface{}) bool

IsEmpty boolean

func IsInList

func IsInList(key int, list []int) bool

IsInList whether a value is in the list

func IsNumberic

func IsNumberic(val interface{}) bool

IsNumberic boolean

func IsObjectEquals

func IsObjectEquals(l interface{}, r interface{}) bool

IsObjectEquals deeply compare two objects that if equals

func IsPathExists

func IsPathExists(path string) bool

IsPathExists check if the path exists

func IsPathNotExists

func IsPathNotExists(path string) bool

IsPathNotExists check if the path not exists

func IsStringMapEquals

func IsStringMapEquals(src, dst map[string]string) bool

IsStringMapEquals boolean

func JSONObjUnmarshal

func JSONObjUnmarshal(in *map[string]interface{}, out interface{}) error

JSONObjUnmarshal unmarshal object

func KebabCaseString

func KebabCaseString(s string) string

KebabCaseString converts XxYy to xx-yy, XxYY to xx-yy

func Md5Encode

func Md5Encode(val string) string

Md5Encode md5 encode

func ObjectIDToString

func ObjectIDToString(val interface{}) string

ObjectIDToString convert objectid to string

func ParsePropertyTagValue

func ParsePropertyTagValue(text string) (string, map[string]string)

ParsePropertyTagValue parse go tag value as property name and attributes

func ParseRemoteIP

func ParseRemoteIP(val string) string

ParseRemoteIP parse remote ip

func PascalCaseString

func PascalCaseString(s string) string

PascalCaseString converts xx_yy to XxYy

func RandomInt

func RandomInt(n int) int

RandomInt random int

func RandomString

func RandomString(l int) string

RandomString random string

func RemoveItemFromList

func RemoveItemFromList(v string, l []string) []string

RemoveItemFromList remove element from list

func SnakeCaseString

func SnakeCaseString(s string) string

SnakeCaseString converts XxYy to xx_yy, XxYY to xx_yy

func SubStringFromUTF8

func SubStringFromUTF8(s string, length int, start int, markDots bool) string

SubStringFromUTF8 sub utf-8 encode string to support chinese text submation this method avoids the traditional []rune() method to optimize the execution time

func SubStringUTF8

func SubStringUTF8(s string, length int, start ...int) string

SubStringUTF8 sub utf-8 encode string to support chinese text submation this method avoids the traditional []rune() method to optimize the execution time

func TimeToHuman

func TimeToHuman(format string, t time.Time) string

TimeToHuman formatter

func TimestampToHuman

func TimestampToHuman(format string, ts int64) string

TimestampToHuman formatter

func TimestampToHumanYYYYMMDD

func TimestampToHumanYYYYMMDD(ts int64) string

TimestampToHumanYYYYMMDD formatter

func ToBoolean

func ToBoolean(val interface{}) bool

ToBoolean converter

func ToDouble

func ToDouble(val interface{}) float64

ToDouble converter

func ToFloat

func ToFloat(val interface{}) float32

ToFloat converter

func ToInt

func ToInt(val interface{}) int

ToInt convert to int

func ToInt64

func ToInt64(val interface{}) int64

ToInt64 converter

func ToString

func ToString(val interface{}) string

ToString convert to string

func ToUint64

func ToUint64(val interface{}) uint64

ToUint64 converter

func URLDecode

func URLDecode(val string) string

URLDecode url decode

func URLEncode

func URLEncode(val string) string

URLEncode url encode

func URLPathJoin

func URLPathJoin(path string, paths ...string) string

URLPathJoin slices

func Utf8ToGbk

func Utf8ToGbk(s []byte) ([]byte, error)

Utf8ToGbk converts utf-8 encoding text into gbk

Types

type CoMapData

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

CoMapData map data for concurrency coroutine operation

func NewCoMapData

func NewCoMapData() *CoMapData

NewCoMapData new a concurrency coroutine operational map data

func (*CoMapData) Add

func (m *CoMapData) Add(key string, value interface{})

Add element

func (*CoMapData) Delete

func (m *CoMapData) Delete(key string)

Remove element

func (*CoMapData) Exists

func (m *CoMapData) Exists(key string) bool

Exists if element exists by key

func (*CoMapData) Get

func (m *CoMapData) Get(key string) (interface{}, bool)

Get element by key

type Timer

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

Timer for processs

func NewTimer

func NewTimer(delayMillisec int64, durationMillisec int64, cb TimerCallback, delegate interface{}) (*Timer, error)

NewTimer and run the timer

func (*Timer) Start

func (p *Timer) Start(delayMillisec int64, durationMillisec int64, cb TimerCallback, delegate interface{}) error

Start the timer

func (*Timer) Stop

func (p *Timer) Stop()

Stop the timer

type TimerCallback

type TimerCallback func(*Timer, time.Time, interface{})

TimerCallback callback

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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