ldc

package
v0.0.0-...-e95b93a Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package ldc implements lodash common util

Index

Constants

View Source
const (
	Id        string = "Id"
	Code      string = "Code"
	Name      string = "Name"
	On        string = "1"
	Off       string = "0"
	ADate            = "2006-01-02"
	ATime            = "15:04:05"
	ADateTime        = "2006-01-02 15:04:05"
	ADateCN          = "2006年01月02日"
	ATimeCN          = "15时04分05秒"
)

Variables

Functions

func AddWait

func AddWait(items []interface{}, call func(interface{}) (interface{}, error),
	duration time.Duration) ([]interface{}, error)

add items then wait group call item timeout

func ConvertType

func ConvertType(source interface{}, target interface{})

convert type for slice

func DefaultToBool

func DefaultToBool(value bool, target bool) bool

default to target if value is zero

func DefaultToByte

func DefaultToByte(value byte, target byte) byte

default to target if value is zero

func DefaultToFloat32

func DefaultToFloat32(value float32, target float32) float32

default to target if value is zero

func DefaultToFloat64

func DefaultToFloat64(value float64, target float64) float64

default to target if value is zero

func DefaultToInt

func DefaultToInt(value int, target int) int

default to target if value is zero

func DefaultToInt16

func DefaultToInt16(value int16, target int16) int16

default to target if value is zero

func DefaultToInt32

func DefaultToInt32(value int32, target int32) int32

default to target if value is zero

func DefaultToInt64

func DefaultToInt64(value int64, target int64) int64

default to target if value is zero

func DefaultToInt8

func DefaultToInt8(value int8, target int8) int8

default to target if value is zero

func DefaultToString

func DefaultToString(value string, target string) string

default to target if value is zero

func DefaultToUint

func DefaultToUint(value uint, target uint) uint

default to target if value is zero

func DefaultToUint16

func DefaultToUint16(value uint16, target uint16) uint16

default to target if value is zero

func DefaultToUint32

func DefaultToUint32(value uint32, target uint32) uint32

default to target if value is zero

func DefaultToUint64

func DefaultToUint64(value uint64, target uint64) uint64

default to target if value is zero

func DefaultToUint8

func DefaultToUint8(value uint8, target uint8) uint8

default to target if value is zero

func DefaultToUintptr

func DefaultToUintptr(value uintptr, target uintptr) uintptr

default to target if value is zero

func FormatTime

func FormatTime(second int64, format string) string

format unix time second, now => time.Now().Unix()

func Go

func Go(call func())

go func no panic, log only

func GoCatch

func GoCatch(call func(), catch func(err interface{}))

go func catch panic

func IfBool

func IfBool(state bool, t bool, f bool) bool

if state true return t else return f

func IfByte

func IfByte(state bool, t byte, f byte) byte

if state true return t else return f

func IfFloat32

func IfFloat32(state bool, t float32, f float32) float32

if state true return t else return f

func IfFloat64

func IfFloat64(state bool, t float64, f float64) float64

if state true return t else return f

func IfInt

func IfInt(state bool, t int, f int) int

if state true return t else return f

func IfInt16

func IfInt16(state bool, t int16, f int16) int16

if state true return t else return f

func IfInt32

func IfInt32(state bool, t int32, f int32) int32

if state true return t else return f

func IfInt64

func IfInt64(state bool, t int64, f int64) int64

if state true return t else return f

func IfInt8

func IfInt8(state bool, t int8, f int8) int8

if state true return t else return f

func IfString

func IfString(state bool, t string, f string) string

if state true return t else return f

func IfUint

func IfUint(state bool, t uint, f uint) uint

if state true return t else return f

func IfUint16

func IfUint16(state bool, t uint16, f uint16) uint16

if state true return t else return f

func IfUint32

func IfUint32(state bool, t uint32, f uint32) uint32

if state true return t else return f

func IfUint64

func IfUint64(state bool, t uint64, f uint64) uint64

if state true return t else return f

func IfUint8

func IfUint8(state bool, t uint8, f uint8) uint8

if state true return t else return f

func IfUintptr

func IfUintptr(state bool, t uintptr, f uintptr) uintptr

if state true return t else return f

func Length

func Length(str string) int

length support chinese

func Location

func Location() string

location for project,file,line,method

func Md5

func Md5(str string) string

str to md5

func ParseBase64

func ParseBase64(str string) string

parse base64

func ParseBase64Err

func ParseBase64Err(str string) (string, error)

parse base64 with err

func ParseHtml

func ParseHtml(htmlStr string) *goquery.Document

parse html

func ParseHtmlErr

func ParseHtmlErr(htmlStr string) (*goquery.Document, error)

parse html with err

func ParseInt

func ParseInt(str string) int

parse int silence

func ParseIntErr

func ParseIntErr(str string) (int, error)

parse int with err

func ParseJwt

func ParseJwt(secret string, jwtStr string) (map[string]interface{}, error)

parse jwt

func ParseObj

func ParseObj(str string, obj interface{})

parse object silence

func ParseObjErr

func ParseObjErr(str string, obj interface{}) error

parse object with err

func ParseStrMap

func ParseStrMap(str string) map[string]string

parse str map silence

func ParseStrObjMap

func ParseStrObjMap(str string) map[string]interface{}

parse str-obj map silence

func ParseTime

func ParseTime(date string) int

to unix silence, format "2006-01-02 15:04:05"

func Substr

func Substr(from string, length int) string

substr support chinese

func SubstrRange

func SubstrRange(from string, startStr string, endStr string) string

substr range

func TemplateGen

func TemplateGen(text string, data interface{}) string

text template gen silence

func TemplateGenErr

func TemplateGenErr(text string, data interface{}) (string, error)

text template gen with err

func TimeSegment

func TimeSegment(start string, end string, seconds int) []string

TimeSegment format 2006-01-02 15:04:05

func ToBase64

func ToBase64(str string) string

str => base64

func ToJson

func ToJson(obj interface{}) string

to json silence

func ToJsonErr

func ToJsonErr(obj interface{}) (string, error)

to json with err

func ToJwt

func ToJwt(secret string, args map[string]interface{}) string

to jwt silence

func ToPercent

func ToPercent(i float64, precision int, suffix string) string

ToPercent(0.123, 3, %) => 12.300%

func ToSliceBool

func ToSliceBool(items []interface{}) []bool

to slice bool

func ToSliceByte

func ToSliceByte(items []interface{}) []byte

to slice byte

func ToSliceFloat32

func ToSliceFloat32(items []interface{}) []float32

to slice float32

func ToSliceFloat64

func ToSliceFloat64(items []interface{}) []float64

to slice float64

func ToSliceInt

func ToSliceInt(items []interface{}) []int

to slice int

func ToSliceInt16

func ToSliceInt16(items []interface{}) []int16

to slice int16

func ToSliceInt32

func ToSliceInt32(items []interface{}) []int32

to slice int32

func ToSliceInt64

func ToSliceInt64(items []interface{}) []int64

to slice int64

func ToSliceInt8

func ToSliceInt8(items []interface{}) []int8

to slice int8

func ToSliceObj

func ToSliceObj(items interface{}) []interface{}

to slice obj

func ToSliceString

func ToSliceString(items []interface{}) []string

to slice string

func ToSliceUint

func ToSliceUint(items []interface{}) []uint

to slice uint

func ToSliceUint16

func ToSliceUint16(items []interface{}) []uint16

to slice uint16

func ToSliceUint32

func ToSliceUint32(items []interface{}) []uint32

to slice uint32

func ToSliceUint64

func ToSliceUint64(items []interface{}) []uint64

to slice uint64

func ToSliceUint8

func ToSliceUint8(items []interface{}) []uint8

to slice uint8

func ToSliceUintptr

func ToSliceUintptr(items []interface{}) []uintptr

to slice uintptr

func ToStr

func ToStr(obj interface{}) string

to str from obj

Types

type Node

type Node struct {
	Id       string
	Name     string
	ParentId string
	Children []*Node
	Ext      interface{}
}

a node item

func ToTree

func ToTree(aList []*Node) []*Node

list to tree

type TP

type TP generic.Type

generic type

func DefaultToTP

func DefaultToTP(value TP, target TP) TP

default to target if value is zero

func IfTP

func IfTP(state bool, t TP, f TP) TP

if state true return t else return f

func ToSliceTP

func ToSliceTP(items []interface{}) []TP

to slice TP

type WaitGroupT

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

wait group for timeout

func NewWaitGroup

func NewWaitGroup() *WaitGroupT

new wait group timeout with default size 1024

func NewWaitGroupSize

func NewWaitGroupSize(size int) *WaitGroupT

new wait group timeout with size

func (*WaitGroupT) Add

func (me *WaitGroupT) Add(call func() (interface{}, error))

add call

func (*WaitGroupT) Wait

func (me *WaitGroupT) Wait(duration time.Duration) ([]interface{}, error)

wait timeout

Jump to

Keyboard shortcuts

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