utils

package
v0.0.0-...-a2bc238 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	BYTE     = 1.0
	KILOBYTE = 1024 * BYTE
	MEGABYTE = 1024 * KILOBYTE
	GIGABYTE = 1024 * MEGABYTE
	TERABYTE = 1024 * GIGABYTE
)

Variables

View Source
var (
	ByteMap = map[float32]string{
		BYTE:     "B",
		KILOBYTE: "KB",
		MEGABYTE: "MB",
		GIGABYTE: "GB",
		TERABYTE: "TB",
	}

	BitPerSecMap = map[float32]string{
		BYTE:     "bps",
		KILOBYTE: "Kbps",
		MEGABYTE: "Mbps",
		GIGABYTE: "Gbps",
		TERABYTE: "Tbps",
	}
)

Functions

func ByteReplace

func ByteReplace(s, old, new []byte, n int) []byte

func BytesToString

func BytesToString(b []byte) string

BytesToString converts byte slice to string.

func CopyMap

func CopyMap(originMap map[string]interface{}) map[string]interface{}

func Float64Cut

func Float64Cut(f float64, prec int) float64

func Float64Round

func Float64Round(f float64, prec int) float64

四舍五入 f 待四舍五入数字 prec 小数点后prec位

func GenerateId

func GenerateId() int64

获取随机长数字串id

func GetFirstNotEmptyString

func GetFirstNotEmptyString(items ...string) string

func GetGOPATH

func GetGOPATH() string

GetGOPATH get the env gopath

func Int64ToString

func Int64ToString(input int64) string

func IsDir

func IsDir(path string) bool

判断所给路径是否为文件夹

func IsNil

func IsNil(src interface{}) bool

func RandomPassword

func RandomPassword(pwdLength int, pwdCodes ...byte) string

RandomPassword 生成随机密码 pwdLength 为密码长度,pwdCodes为密码生成字符范围,不传使用默认值

func RandomStrings

func RandomStrings(length int, from string) string

func SliceCut

func SliceCut(v interface{}, offset int, limit int) error

func Stack

func Stack(skip int) []byte

stack returns a nicely formatted stack frame, skipping skip frames.

func StorageUnitConvert

func StorageUnitConvert(bytes uint64, unitMap ...map[float32]string) string

func StringArrayContains

func StringArrayContains(s []string, e string) bool

Deprecated, use github.com/duke-git/lancet/v2/slice instead.

func StringArrayDiff

func StringArrayDiff(m, n []string) []string

Deprecated, use github.com/duke-git/lancet/v2/slice instead.

func StringArrayUnique

func StringArrayUnique(m []string) []string

Deprecated, use github.com/duke-git/lancet/v2/slice instead.

func StringContainsOne

func StringContainsOne(src string, items ...string) bool

Deprecated, use github.com/duke-git/lancet/v2/slice instead.

func StringReplace

func StringReplace(base, oldS, newS string, n int) string

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes converts string to byte slice.

func StringsToInterfaces

func StringsToInterfaces(src []string) []interface{}

func ToCamel

func ToCamel(s string) string

Converts a string to CamelCase

func ToDelimited

func ToDelimited(s string, del uint8) string

Converts a string to delimited.snake.case (in this case `del = '.'`)

func ToInt64

func ToInt64(value interface{}) (d int64)

func ToKebab

func ToKebab(s string) string

Converts a string to kebab-case

func ToLowerCamel

func ToLowerCamel(s string) string

Converts a string to lowerCamelCase

func ToScreamingDelimited

func ToScreamingDelimited(s string, del uint8, screaming bool) string

Converts a string to SCREAMING.DELIMITED.SNAKE.CASE (in this case `del = '.'; screaming = true`) or delimited.snake.case (in this case `del = '.'; screaming = false`)

func ToScreamingKebab

func ToScreamingKebab(s string) string

Converts a string to SCREAMING-KEBAB-CASE

func ToScreamingSnake

func ToScreamingSnake(s string) string

Converts a string to SCREAMING_SNAKE_CASE

func ToSnake

func ToSnake(s string) string

Converts a string to snake_case

func TrimBlankLines

func TrimBlankLines(text string) string

Remove blank lines from a string

func XMLDecode

func XMLDecode(data []byte, obj interface{}) error

func XMLEncode

func XMLEncode(obj interface{}) ([]byte, error)

Types

This section is empty.

Directories

Path Synopsis
join
cmd
cmd

Jump to

Keyboard shortcuts

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