utils

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MININTSTR string = "0000000000000000000000"
	MAXINTSTR string = "9999999999999999999999"
)

Functions

func Base64Encode

func Base64Encode(str string) string

func Bytes2String added in v1.4.0

func Bytes2String(b []byte) (s string)

func Dir

func Dir() string

func Exist

func Exist(file string) bool

func GetBetweenStr

func GetBetweenStr(str, start, end string) string

func GetExistPath

func GetExistPath(path string) string

func InSlice

func InSlice(v string, sl []string) bool

func InSliceIface

func InSliceIface(v interface{}, sl []interface{}) bool

func InSliceIfaceToLower

func InSliceIfaceToLower(v string, sl interface{}) (bool, error)

func InterfacesToStrings

func InterfacesToStrings(items []interface{}) (s []string)

func Keys

func Keys(maps map[string]interface{}) []string

func ListDir

func ListDir(path string) ([]string, error)

func Max

func Max(a, b int) int

func MaxFloat64

func MaxFloat64(a, b float64) float64

func Md5Encode

func Md5Encode(str string) string

func Merge

func Merge(mapsA map[string]string, mapsB map[string]string) (map[string]string, error)

func Min added in v1.0.2

func Min(a, b int) int

func MinFloat64

func MinFloat64(a, b float64) float64

func MkDir

func MkDir(path string) error

func MkDirIfNotExist

func MkDirIfNotExist(path string) error

func Path

func Path() string

func Pwd

func Pwd() string

func RandSleep

func RandSleep(max, min int)

ms

func RemoveDir

func RemoveDir(path string) error

func RemoveFile

func RemoveFile(file string) error

func ReplayMaxStr

func ReplayMaxStr(size int) string

func ReplayStr

func ReplayStr(i int, size int) string

func SStrings

func SStrings(param []string) map[string]bool

func SearchFile

func SearchFile(filename string, paths ...string) (fullpath string, err error)

func SliceDiff

func SliceDiff(slice1, slice2 []interface{}) (diffslice []interface{})

func SliceFilter

func SliceFilter(slice []interface{}, a filtertype) (ftslice []interface{})

func SliceMerge

func SliceMerge(slice1, slice2 []interface{}) (c []interface{})

func SliceRand

func SliceRand(a []interface{}) (b interface{})

func SliceRandList

func SliceRandList(min, max int) []int

func SliceRange

func SliceRange(start, end, step int64) (intslice []int64)

func SliceReduce

func SliceReduce(slice []interface{}, a reducetype) (dslice []interface{})

func SliceShuffle

func SliceShuffle(slice []interface{}) []interface{}

func SliceSum

func SliceSum(intslice []int64) (sum int64)

func Sort

func Sort(maps map[string]string) map[string]string

func SortKey

func SortKey(maps []string) []string

func String2Bytes added in v1.4.0

func String2Bytes(s string) (b []byte)

func Strings

func Strings(param []interface{}) map[string]bool

func Substr

func Substr(str string, start, length int) string

func ToMapStrings

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

func ToParam

func ToParam(param url.Values) map[string]string

func ToSlice

func ToSlice(arr interface{}) ([]interface{}, error)

func ToStringDict

func ToStringDict(items []interface{}, key string) ([]string, error)

func ToStrings

func ToStrings(arr []interface{}) []string

func ToTime

func ToTime(str string) (time.Time, error)

func ToValues

func ToValues(param map[string]string) url.Values

func Uint16Decode added in v1.1.1

func Uint16Decode(src []byte) uint16

func Uint16Encode added in v1.1.1

func Uint16Encode(dst []byte, u uint16) []byte

func Urldecode

func Urldecode(str string) (string, error)

func Urlencode

func Urlencode(str string) string

func Values

func Values(maps map[string]interface{}) []interface{}

func Version_compare

func Version_compare(version1, version2 string) int

Usage

Utils.CompareSimple("1.2", "1.0.1")
Returns: 1

Utils.CompareSimple("1.0rc1", "1.0")
Returns: -1

func WildcardMatch

func WildcardMatch(pattern, name string) bool

func WildcardMatchSimple

func WildcardMatchSimple(pattern, name string) bool

Types

type Duration

type Duration time.Duration

func (Duration) Duration

func (d Duration) Duration() time.Duration

func (Duration) MarshalText

func (d Duration) MarshalText() (text []byte, err error)

func (Duration) String

func (d Duration) String() string

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

See https://github.com/BurntSushi/toml

type TimerPool added in v1.1.1

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

func NewTimerPool added in v1.1.1

func NewTimerPool() *TimerPool

func (*TimerPool) Get added in v1.1.1

func (tp *TimerPool) Get(d time.Duration) *time.Timer

Get returns a timer for the given duration d from the pool.

Return back the timer to the pool with Put.

func (*TimerPool) Put added in v1.1.1

func (tp *TimerPool) Put(t *time.Timer)

Put returns t to the pool.

t cannot be accessed after returning to the pool.

type Timestamp

type Timestamp struct {
	time.Time
}

func (Timestamp) Equal

func (t Timestamp) Equal(u Timestamp) bool

Equal reports whether t and u are equal based on time.Equal

func (Timestamp) String

func (t Timestamp) String() string

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface. Time is expected in RFC3339 or Unix format.

Jump to

Keyboard shortcuts

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