utils

package module
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2021 License: Apache-2.0 Imports: 22 Imported by: 2

README

utils

golang工具包

string

String2Int(s, default string) int

String2Int8(s, default string) int8

String2Int32(s, default string) int32

String2Int64(s, default string) int64

String2Uint(s, default string) uint

String2Uint8(s, default string) uint8

String2Uint32(s, default string) uint32

String2Uint64(s, default string) uint64

String2Float(s string, defaultVal float64) float64

Int2String(i int) string

Int642String(i int) string

Int2String(i int) string

Float2String(f float) string

IsValidPhoneNum(s sting) bool

IdCardToHideString(s string) string

PhoneToHideString(s string) string

VerifyEmailFormat(email string) bool

EmailToHideString(s string) string

Utf8SubStr(str string, start, length int) (string, error)

mapper

the mapper get value through key

func name like ReadWith{type}

ReadWithString、ReadWithInt64、ReadWithSlice、ReadWithMap any more

only support basic type with go

example:

mp := NewMapperReader(map[string]interface{}{
    "foo":"123",
    "bar":4567
})
assert(mp.ReadWithString("bar", ""), "4567")
assert(mp.ReadWithInt64("foo", ""), 123)

convert

BasicTypeToString(value interface{}) string

BasicTypeToInt64(value interface{}) int64

utils

//use json.number

UnmarshalNumber(bt []byte, v interface{}) error

//html tag

Marshal(v interface{}) ([]byte, error)

GetCurrentPath() string

GetLocalIP() string

changeLog

v1.0.1

add MapReader

v1.0.2

add id worker

v1.0.1

reflect

v1.1.4

struct 2 map changed

v1.1.5

interface to string|int64

Documentation

Index

Constants

View Source
const IntItemTyp = 3
View Source
const ListItemType = 2
View Source
const StringItemTyp = 1

Variables

View Source
var ArrayMapKexIsEmpty = "slice empty"
View Source
var ArrayMapKexNotExists = "key not exists"

* Like Php Array method ArrayKeysString(slices []ArrayMap, key string) []string ArrayKeysInt64(slices []ArrayMap, key string) []int64 ArrayKeysInt(slices []ArrayMap, key string) []int ArrayColumns(slices []ArrayMap, key string) []interface{} ArrayColumnValue(slices []ArrayMap, key string, index string) (map[string]interface{}, error) ArrayColumnValues(slices []ArrayMap, key string) (map[string]ArrayMap, error) InArrayInt64(slice []int64, value int64) int InArrayInt(slice []int, value int) int InArrayString(slice []string, value string) int RemoveRepeatedInt(values []int) []int RemoveRepeatedInt64(values []int64) []int64 RemoveRepeatedString(values []string) []string

Functions

func Abs

func Abs(n int64) int64

func AbsFloat

func AbsFloat(n float64) float64

func ArrayColumnValue added in v1.1.7

func ArrayColumnValue(slices []ArrayMap, key string, index string) (map[string]interface{}, error)

func ArrayColumnValues added in v1.1.7

func ArrayColumnValues(slices []ArrayMap, key string) (map[string]ArrayMap, error)

func ArrayColumns added in v1.1.7

func ArrayColumns(slices []ArrayMap, key string) []interface{}

func ArrayKeysInt added in v1.1.7

func ArrayKeysInt(slices []ArrayMap, key string) []int

func ArrayKeysInt64 added in v1.1.7

func ArrayKeysInt64(slices []ArrayMap, key string) []int64

func ArrayKeysString added in v1.1.7

func ArrayKeysString(slices []ArrayMap, key string) []string

func B2S

func B2S(bs []uint8) string

[]uint8 to string

func Base64Decode added in v1.1.7

func Base64Decode(input string, typ int8) (string, error)

base64编码 1 - 表示字符串,2 - 表示uri

func Base64Encode added in v1.1.7

func Base64Encode(input string, typ int8) string

base64编码 1 - 表示字符串,2 - 表示uri

func BasicTypeToInt64 added in v1.1.5

func BasicTypeToInt64(value interface{}) (i int64)

Itoa converts an interface to a string.

func BasicTypeToString added in v1.1.5

func BasicTypeToString(value interface{}) (s string)

Itoa converts an interface to a string.

func BytesToString

func BytesToString(b []byte) string

BytesToString converts byte slice to string.

func CompareVersion added in v1.1.7

func CompareVersion(v1, v2 string) int

func CovertTime

func CovertTime(timestamp int64) time.Time

获取本地时间

func EmailToHideString added in v1.1.7

func EmailToHideString(s string) string

转换email中间中间的字符

func EncodeMd5 added in v1.1.7

func EncodeMd5(s string, salt string) string

加盐的字符处理为md5

func Float2String

func Float2String(a float64) string

func GetCurrentPath

func GetCurrentPath() string

func GetLocalIP

func GetLocalIP() string

func GetNNSecond

func GetNNSecond() int64

获取纳秒数据

func GetNSecond

func GetNSecond() int64

获取毫秒数据

func GetNowDayFinishTime

func GetNowDayFinishTime() time.Time

获取当天的结束时间

func GetNowDayStartTime

func GetNowDayStartTime() time.Time

获取当天的起始时间

func GetRandomNumString added in v1.1.7

func GetRandomNumString(cnum int) string

获取数字字符串

func GetRandomString added in v1.1.7

func GetRandomString(cnum int) string

获取随机字符串

func GetRequestKey

func GetRequestKey(r *http.Request, key string) string

获取参数,不支持keys 0

func GetSecond

func GetSecond() int64

获取秒数据

func GetTimeString

func GetTimeString() string

获取具体时间String

func HideMbStr added in v1.1.7

func HideMbStr(s string, subLen int) string

func IPStringToInt

func IPStringToInt(ipString string) int

func IdCardToHideString added in v1.1.7

func IdCardToHideString(s string) string

身份证中间的字符

func InArrayInt added in v1.1.7

func InArrayInt(slice []int, value int) int

func InArrayInt64 added in v1.1.7

func InArrayInt64(slice []int64, value int64) int

func InArrayString added in v1.1.7

func InArrayString(slice []string, value string) int

func Int2String

func Int2String(a int) string

func Int642String

func Int642String(a int64) string

func Int82String

func Int82String(a int8) string

func Interface2Int added in v1.1.7

func Interface2Int(value interface{}) (s int)

interface => int

func Interface2Int64 added in v1.1.7

func Interface2Int64(value interface{}) (s int64)

interface => int64

func Interface2String added in v1.1.7

func Interface2String(value interface{}) (s string)

interface => string

func IsValidPhoneNum added in v1.1.7

func IsValidPhoneNum(phone string) bool

判断手机号是否合法

func JoinString added in v1.1.7

func JoinString(s []string, d string) string

拼接字符串

func Map2Struct added in v1.0.1

func Map2Struct(m map[string]interface{}, obj interface{}) error

obj must use *point

func MapInterfaceToMapString added in v1.1.8

func MapInterfaceToMapString(mp map[string]interface{}) (res map[string]interface{})

* 任意map类型全部转为string,包含key、value,接口中常用

func Marshal

func Marshal(v interface{}) ([]byte, error)

func NextId added in v1.1.4

func NextId() int64

func PhoneToHideString added in v1.1.7

func PhoneToHideString(s string) string

转换手机号中间中间的字符

func RemoveRepeatedInt added in v1.1.7

func RemoveRepeatedInt(values []int) []int

func RemoveRepeatedInt64 added in v1.1.7

func RemoveRepeatedInt64(arr []int64) (newArr []int64)

func RemoveRepeatedString added in v1.1.7

func RemoveRepeatedString(values []string) []string

func SliceBuildWithInterface

func SliceBuildWithInterface(v interface{}) reflect.Value

func SplitString added in v1.1.7

func SplitString(s string, d string) []string

分割字符串

func String2Float

func String2Float(s string, defaultVal float64) float64

func String2Int

func String2Int(s string, defaultVal int) int

转换默认值

func String2Int64

func String2Int64(s string, defaultVal int64) int64

func String2Int8

func String2Int8(s string, defaultVal int8) int8

func String2Time

func String2Time(s string) time.Time

func String2TimeD

func String2TimeD(s string) time.Time

func String2Uint64

func String2Uint64(s string, defaultVal uint64) uint64

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes converts string to byte slice.

func Struct2Map added in v1.0.1

func Struct2Map(obj interface{}) map[string]interface{}

func Struct2MapList added in v1.0.1

func Struct2MapList(obj interface{}) ([]map[string]interface{}, error)

func StructExistsProperty

func StructExistsProperty(s interface{}, key string) bool

func StructSetFieldValue

func StructSetFieldValue(v interface{}, key string, value interface{}) bool

set struct field value example: type e struct{ N string } e1 := &e{N:"222"} e1, ok := StructSetFieldValue(e1, "N", "fff") params v must ues ptr type

func Time2StringByNow

func Time2StringByNow() string

获取当前的时间

func Time2StringD

func Time2StringD(t time.Time) string

时间转换 -> 天

func Time2StringH

func Time2StringH(t time.Time) string

时间转换 -> 小时

func Time2StringM

func Time2StringM(t time.Time) string

时间转换 -> 分钟

func Time2StringS

func Time2StringS(t time.Time) string

时间转换 -> 秒

func Uint642String

func Uint642String(a uint64) string

func UnmarshalNumber added in v1.1.6

func UnmarshalNumber(bt []byte, v interface{}) error

func Utf8SubStr

func Utf8SubStr(str string, start, length int) (string, error)

func VerifyEmailFormat added in v1.1.7

func VerifyEmailFormat(email string) bool

验证邮箱

func VersionCompare added in v1.1.7

func VersionCompare(ver1, ver2 string) (int, error)

比较两个依赖的版本大小 如果成功,返回比较结果,如果失败,返回错误原因 如果两个版本相同,返回 0 如果第一个版本大于第二个版本,返回 1 如果第一个版本小于第二个版本,返回 -1

func VersionParser added in v1.1.7

func VersionParser(version string) ([]string, error)

解析 pom.xml 中的版本

Types

type ArrayMap added in v1.1.7

type ArrayMap map[string]interface{}

func (ArrayMap) ExistsKey added in v1.1.7

func (am ArrayMap) ExistsKey(key string) bool

type IntItem added in v1.1.7

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

func (*IntItem) CompareTo added in v1.1.7

func (i *IntItem) CompareTo(item Item) int

switch ( item.getType() ) { case INT_ITEM: int itemValue = ( (IntItem) item ).value; return Integer.compare( value, itemValue ); case LONG_ITEM: case BIGINTEGER_ITEM: return -1;

case STRING_ITEM: return 1; // 1.1 > 1-sp

case LIST_ITEM: return 1; // 1.1 > 1-1

default: throw new IllegalStateException( "invalid item: " + item.getClass() ); }

func (*IntItem) GetType added in v1.1.7

func (i *IntItem) GetType() int

func (*IntItem) IsNull added in v1.1.7

func (i *IntItem) IsNull() bool

type Item added in v1.1.7

type Item interface {
	CompareTo(item Item) int
	GetType() int
	IsNull() bool
}

type MapReader added in v1.0.1

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

func NewMapperReader added in v1.0.1

func NewMapperReader(m map[string]interface{}) *MapReader

func (*MapReader) GetValue added in v1.1.4

func (m *MapReader) GetValue() map[string]interface{}

func (*MapReader) ReadWithBool added in v1.0.1

func (m *MapReader) ReadWithBool(key string, defaultVal bool) bool

func (*MapReader) ReadWithInt added in v1.0.1

func (m *MapReader) ReadWithInt(key string, defaultVal int) int

func (*MapReader) ReadWithInt32 added in v1.0.1

func (m *MapReader) ReadWithInt32(key string, defaultVal int32) int32

func (*MapReader) ReadWithInt64 added in v1.0.1

func (m *MapReader) ReadWithInt64(key string, defaultVal int64) int64

func (*MapReader) ReadWithInt8 added in v1.0.1

func (m *MapReader) ReadWithInt8(key string, defaultVal int8) int8

func (*MapReader) ReadWithInterface added in v1.0.1

func (m *MapReader) ReadWithInterface(key string, defaultVal interface{}) interface{}

func (*MapReader) ReadWithMap added in v1.0.1

func (m *MapReader) ReadWithMap(key string) map[string]interface{}

func (*MapReader) ReadWithSlice added in v1.0.1

func (m *MapReader) ReadWithSlice(key string) []interface{}

func (*MapReader) ReadWithString added in v1.0.1

func (m *MapReader) ReadWithString(key string, defaultVal string) string

func (*MapReader) ReadWithUint added in v1.0.1

func (m *MapReader) ReadWithUint(key string, defaultVal uint) uint

func (*MapReader) ReadWithUint16 added in v1.0.1

func (m *MapReader) ReadWithUint16(key string, defaultVal uint16) uint16

func (*MapReader) ReadWithUint64 added in v1.0.1

func (m *MapReader) ReadWithUint64(key string, defaultVal uint64) uint64

func (*MapReader) ReadWithUint8 added in v1.0.1

func (m *MapReader) ReadWithUint8(key string, defaultVal uint8) uint8

Jump to

Keyboard shortcuts

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