util4go

package module
v1.0.51 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2022 License: Apache-2.0 Imports: 20 Imported by: 5

README

boot4go-util

a utility toolkit for golang

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ArrayOverFlow = errors.New("ArrayOverFlow")
View Source
var Counter uint32
View Source
var MachineID = ReadMachineID()
View Source
var Pid = os.Getpid()
View Source
var RegExpPool = make(regExpPool)

Functions

func BinarySearch

func BinarySearch(a []string, v interface{}) int

func BuildFormatString

func BuildFormatString(format string, a ...any) string

func BuildString

func BuildString(a ...any) string

func BytesToInt added in v1.0.20

func BytesToInt[T int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64](bytesArr []byte) T

BytesToInt 将以Big端存储的长为1/2字节的数转化成int类型的数

func BytesToIntEndian added in v1.0.20

func BytesToIntEndian[T int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64](bytesArr []byte, endian Endian) T

func BytesToString added in v1.0.32

func BytesToString(b []byte) string

BytesToString converts byte slice to a string without memory allocation.

Note it may break if the implementation of string or slice header changes in the future go versions.

func Collect added in v1.0.24

func Collect[T any, V any](source []T, fn func(one T) V) []V

func Copy added in v1.0.16

func Copy[T any](src *T) *T

func CopyArray added in v1.0.5

func CopyArray[T any](src []any, dest []T) []T

func DecodeByte added in v1.0.43

func DecodeByte(b []byte, start int) (byte, error)

func DecodeUint16 added in v1.0.43

func DecodeUint16(b []byte, start int) (uint16, error)

func DecodeUint32 added in v1.0.43

func DecodeUint32(b []byte, start int) (uint32, error)

func ElmType

func ElmType(value reflect.Value) reflect.Type

func EncodeUint16 added in v1.0.43

func EncodeUint16(i uint16) []byte

func EncodeUint32 added in v1.0.43

func EncodeUint32(i uint32) []byte

func EndsWith added in v1.0.41

func EndsWith(s []byte, target []byte) bool

func GetBool added in v1.0.25

func GetBool(s string) (bool, error)

func GetBool2 added in v1.0.28

func GetBool2(s string, defaultValue bool) bool

func GetConnIP4 added in v1.0.33

func GetConnIP4(c net.Conn) net.IP

func GetFloat added in v1.0.25

func GetFloat(s string) (float64, error)

func GetFloat2 added in v1.0.28

func GetFloat2(s string, defaultValue float64) float64

func GetIPv4ByInterface added in v1.0.4

func GetIPv4ByInterface(name string) ([]string, error)

GetIPv4ByInterface return IPv4 address from a specific interface IPv4 addresses

func GetITime added in v1.0.28

func GetITime(s string, layout string, defaultValue *time.Time) *time.Time

func GetInt added in v1.0.25

func GetInt(s string) (int64, error)

func GetInt2 added in v1.0.28

func GetInt2(s string, defaultValue int64) int64

func GetMapValue added in v1.0.28

func GetMapValue[K Keyable, T any](m map[K]T, key K) T

func GetMapValue2 added in v1.0.28

func GetMapValue2[K Keyable, T any](m map[K]T, key K, defaultValue T) T

func GetRandomUUID added in v1.0.43

func GetRandomUUID() string

func GetUint added in v1.0.25

func GetUint(s string) (uint64, error)

func GetUint2 added in v1.0.28

func GetUint2(s string, defaultValue uint64) uint64

func GetUint32IP added in v1.0.33

func GetUint32IP(c net.Conn) uint32

func GroupBy added in v1.0.24

func GroupBy[T any, K Keyable](source []T, fn func(one T) K) map[K][]T

func GuessIP added in v1.0.4

func GuessIP(remote string) *string

GuessIP 获取连接远程的本地ip

func IP added in v1.0.16

func IP(ip string) string

func InsertAt added in v1.0.19

func InsertAt[T any](list []T, idx int, t T) []T

func Int64ToStr

func Int64ToStr(i int64) string

Int64ToStr int64 to str

func IntToBytes added in v1.0.20

func IntToBytes[T int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64](intNum T) []byte

IntToBytes 将int类型的数转化为字节并以Big端存储

func IntToBytesEndian added in v1.0.20

func IntToBytesEndian[T int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64](intNum T, endian Endian) []byte

IntToBytesEndian 将int类型的数转化为字节并以Big端存储

func Ip2uint32 added in v1.0.33

func Ip2uint32(ip net.IP) uint32

func IsEmpty

func IsEmpty(str string) bool

func IsNull added in v1.0.43

func IsNull[T any](v1 *T, fn func() T) T

func IsUTF8 added in v1.0.43

func IsUTF8(p []byte) bool

func LeftPad

func LeftPad(str string, limit int, placeholder rune) string

func LocalIPv4s added in v1.0.4

func LocalIPv4s() ([]string, error)

LocalIPv4s 获取本地内网ip LocalIPs return all non-loopback IPv4 addresses

func MD5

func MD5(data string) string

func Map added in v1.0.24

func Map[T any, K Keyable](source []T, fn func(T) K) map[K]T

func MapStream added in v1.0.24

func MapStream[T any, K Keyable](source map[K]T, fn func(K, T))

func NewInstanceValue

func NewInstanceValue(t reflect.Type) reflect.Value

func Null2Default added in v1.0.43

func Null2Default[T any](v1 *T, v2 T) T

func ParseParameterName

func ParseParameterName(str string) []string

func ParseURL added in v1.0.22

func ParseURL(url string) (schema, host, query string, rtnErr error)

func PrintSlice added in v1.0.41

func PrintSlice[T any](b []T)

func RandRune added in v1.0.12

func RandRune() rune

func RandRune2 added in v1.0.12

func RandRune2(s, e rune) rune

func ReadMachineID added in v1.0.43

func ReadMachineID() []byte

func Reduce

func Reduce[T any, R any](source []T, fn func(one T) (R, bool)) []R

func ReleasePerIPConn added in v1.0.33

func ReleasePerIPConn(c *PerIPConn)

func RemoveAt added in v1.0.19

func RemoveAt[T any](list []T, idx int) []T

func ReplaceAt added in v1.0.19

func ReplaceAt[T any](list []T, idx int, t T) []T

func ReplaceIP added in v1.0.10

func ReplaceIP(address, ip string) string

ReplaceIP 获取连接远程的本地ip

func ReplaceParameterValue

func ReplaceParameterValue(str string, keyAndValue map[string]string) string

func ReplaceParameterWithKeyValue

func ReplaceParameterWithKeyValue(str string, keyAndValue map[string]string) string

func ReplacePort added in v1.0.17

func ReplacePort(address, port string) string

func Reverse added in v1.0.25

func Reverse[T any](source []T) []T

func RightPad added in v1.0.11

func RightPad(str string, limit int, placeholder rune) string

func SaltMd5

func SaltMd5(data, salt string) string

func SetUnExportFieldValue added in v1.0.21

func SetUnExportFieldValue[T any](obj *T, field string, data any) (rtnErr error)

func SplitHostPort added in v1.0.16

func SplitHostPort(address string) (host, port string, err error)

func StartsWith added in v1.0.41

func StartsWith(s []byte, target []byte) bool

func Str2Bool

func Str2Bool(source string) (any, error)

func Str2Float32

func Str2Float32(source string) (any, error)

func Str2Float64

func Str2Float64(source string) (any, error)

func Str2Int

func Str2Int(source string) (any, error)

func Str2Int16

func Str2Int16(source string) (any, error)

func Str2Int32

func Str2Int32(source string) (any, error)

func Str2Int64

func Str2Int64(source string) (any, error)

func Str2Int8

func Str2Int8(source string) (any, error)

func Str2Object

func Str2Object(v string, k reflect.Kind) (any, error)

func Str2UInt64

func Str2UInt64(source string) (any, error)

func Str2Uint

func Str2Uint(source string) (any, error)

func Str2Uint16

func Str2Uint16(source string) (any, error)

func Str2Uint32

func Str2Uint32(source string) (any, error)

func Str2Uint8

func Str2Uint8(source string) (any, error)

func StrNumSuffixInt

func StrNumSuffixInt(str string, mult int) int

StrNumSuffixInt Parse a number with K/M/G suffixes based on thousands (1000) or 2^10 (1024)

func Stream added in v1.0.24

func Stream[T any](source []T, fn func(one T))

func String

func String(obj any) string

func StringToBytes added in v1.0.32

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

StringToBytes converts string to a byte slice without memory allocation.

Note it may break if the implementation of string or slice header changes in the future go versions.

func Substring

func Substring(source string, start int, end int) string

func Type2Str

func Type2Str(t reflect.Type) (string, error)

func TypeOf

func TypeOf(obj any) reflect.Type

func Uint322ip added in v1.0.33

func Uint322ip(ip uint32) net.IP

func Values added in v1.0.24

func Values[T any, K Keyable](source map[K]T) []T

Types

type DeString added in v1.0.28

type DeString interface {
	int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64 | string
}

type Dimension added in v1.0.24

type Dimension struct {
	M1  string
	M15 string
	M30 string
	M60 string

	LM1  string
	LM15 string
	LM30 string
	LM60 string
}

func Time2Dimension added in v1.0.24

func Time2Dimension(t time.Time) (*Dimension, error)

type Endian added in v1.0.20

type Endian int8
const (
	LittleEndian Endian = iota
	BigEndian
)

type Keyable added in v1.0.24

type Keyable interface {
	int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | uintptr | float32 | float64 | complex64 | complex128 | string
}

type Numeric added in v1.0.25

type Numeric interface {
	int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | uintptr | float32 | float64 | complex64 | complex128
}

type PerIPConn added in v1.0.33

type PerIPConn struct {
	net.Conn
	// contains filtered or unexported fields
}

func AcquirePerIPConn added in v1.0.33

func AcquirePerIPConn(conn net.Conn, ip uint32, counter *PerIPConnCounter) *PerIPConn

func (*PerIPConn) Close added in v1.0.33

func (c *PerIPConn) Close() error

type PerIPConnCounter added in v1.0.33

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

func (*PerIPConnCounter) Register added in v1.0.33

func (cc *PerIPConnCounter) Register(ip uint32) int

func (*PerIPConnCounter) Unregister added in v1.0.33

func (cc *PerIPConnCounter) Unregister(ip uint32)

type RegExpError added in v1.0.13

type RegExpError struct {
}

func (RegExpError) Error added in v1.0.13

func (e RegExpError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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