utils

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2023 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 added in v0.2.6

func CamelCaseSlices(s string) []string

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

func CamelCaseString added in v0.2.0

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 added in v0.2.3

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 added in v0.2.6

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

FormDataCopyFields copy form data fields into db model fields

func GB18030ToUtf8 added in v0.2.2

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

GB18030ToUtf8 converts gbk encoding text into utf-8

func GB2312ToUtf8 added in v0.2.2

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

GB2312ToUtf8 converts gbk encoding text into utf-8

func GbkToUtf8 added in v0.2.2

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 added in v0.2.0

func HashCode(content []byte) uint32

HashCode hashes a buffer to a unique hashcode

func HashCodeAsInt added in v0.2.0

func HashCodeAsInt(content []byte) int

HashCodeAsInt hashes a buffer to a unique hashcode

func HumanByteSize added in v0.2.3

func HumanByteSize(bs int) string

HumanByteSize convert byte size as human recognizable

func HumanByteText added in v0.2.7

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 added in v0.2.6

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 added in v0.2.0

func IsNumberic(val interface{}) bool

IsNumberic boolean

func IsObjectEquals added in v0.2.0

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

IsObjectEquals deeply compare two objects that if equals

func IsPathExists added in v0.2.0

func IsPathExists(path string) bool

IsPathExists check if the path exists

func IsPathNotExists added in v0.2.0

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 added in v0.2.0

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 added in v0.2.0

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 added in v0.2.0

func PascalCaseString(s string) string

PascalCaseString converts xx_yy to XxYy

func RandomInt added in v0.2.2

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 added in v0.2.0

func SnakeCaseString(s string) string

SnakeCaseString converts XxYy to xx_yy, XxYY to xx_yy

func SubStringFromUTF8 added in v0.2.3

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 added in v0.2.3

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 added in v0.2.5

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

URLPathJoin slices

func Utf8ToGbk added in v0.2.2

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

Utf8ToGbk converts utf-8 encoding text into gbk

Types

type CoMapData added in v0.2.6

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

CoMapData map data for concurrency coroutine operation

func NewCoMapData added in v0.2.6

func NewCoMapData() *CoMapData

NewCoMapData new a concurrency coroutine operational map data

func (*CoMapData) Add added in v0.2.6

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

Add element

func (*CoMapData) Delete added in v0.2.6

func (m *CoMapData) Delete(key string)

Remove element

func (*CoMapData) Exists added in v0.2.6

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

Exists if element exists by key

func (*CoMapData) Get added in v0.2.6

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

Get element by key

type Timer added in v0.2.5

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

Timer for processs

func NewTimer added in v0.2.5

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

NewTimer and run the timer

func (*Timer) Start added in v0.2.5

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

Start the timer

func (*Timer) Stop added in v0.2.5

func (p *Timer) Stop()

Stop the timer

type TimerCallback added in v0.2.5

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