utils

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultTrimChars are the characters which are stripped by Trim* functions in default.
	DefaultTrimChars = string([]byte{
		'\t',
		'\v',
		'\n',
		'\r',
		'\f',
		' ',
		0x00,
		0x85,
		0xA0,
	})
)

Functions

func ArrayToString

func ArrayToString(array []interface{}) string

func Decrypt added in v0.0.2

func Decrypt(privateKeyFile, ciphertext string, types string) (plaintext string, err error)

Decrypt 使用私钥解密数据

func DecryptOAEP added in v0.0.2

func DecryptOAEP(privateKeyFile, ciphertext string) (plaintext string, err error)

DecryptOAEP 使用私钥解密数据

func DecryptPKCS1v15 added in v0.0.2

func DecryptPKCS1v15(privateKeyFile, ciphertext string) (plaintext string, err error)

DecryptPKCS1v15 使用私钥解密数据

func Encrypt added in v0.0.2

func Encrypt(privateKeyFile, ciphertext string, types string) (plaintext string, err error)

Encrypt 使用公钥加密数据

func EncryptOAEP added in v0.0.2

func EncryptOAEP(publicKeyFile string, content string) (ciphertext string, err error)

EncryptOAEP 使用公钥加密数据

func EncryptPKCS1v15 added in v0.0.2

func EncryptPKCS1v15(publicKeyFile string, content string) (ciphertext string, err error)

EncryptPKCS1v15 使用公钥加密数据

func EncryptPassword added in v0.0.2

func EncryptPassword(password string, salt string) (string, error)

func EncryptString added in v0.0.2

func EncryptString(data string) (encrypt string, err error)

EncryptString encrypts `data` using MD5 algorithms.

func EqualFoldWithoutChars

func EqualFoldWithoutChars(s1, s2 string) bool

EqualFoldWithoutChars checks string `s1` and `s2` equal case-insensitively, with/without chars '-'/'_'/'.'/' '.

func FormatCmdKey

func FormatCmdKey(s string) string

FormatCmdKey formats string `s` as command key using uniformed format.

func FormatEnvKey

func FormatEnvKey(s string) string

FormatEnvKey formats string `s` as environment key using uniformed format.

func GenerateKeyPair added in v0.0.2

func GenerateKeyPair(bits int, privateKeyFile string, publicKeyFile string) (err error)

GenerateKeyPair 生成RSA密钥对

func IpInBlackListRange added in v0.0.2

func IpInBlackListRange(ip string, ipList []string) (result bool)

IpInBlackListRange 判断IP是否在黑名单

func IsDebugEnabled

func IsDebugEnabled() bool

IsDebugEnabled checks and returns whether debug mode is enabled. The debug mode is enabled when command argument "gf.debug" or environment "GF_DEBUG" is passed.

func IsEmpty

func IsEmpty(value interface{}) bool

IsEmpty checks whether `value` is empty.

func IsFloat

func IsFloat(value interface{}) bool

IsFloat checks whether `value` is type of float.

func IsInt

func IsInt(value interface{}) bool

IsInt checks whether `value` is type of int.

func IsLetter

func IsLetter(b byte) bool

IsLetter checks whether the given byte b is a letter.

func IsLetterLower

func IsLetterLower(b byte) bool

IsLetterLower checks whether the given byte b is in lower case.

func IsLetterUpper

func IsLetterUpper(b byte) bool

IsLetterUpper checks whether the given byte b is in upper case.

func IsMap

func IsMap(value interface{}) bool

IsMap checks whether `value` is type of map.

func IsNil

func IsNil(value interface{}) bool

IsNil checks whether `value` is nil, especially for interface{} type value.

func IsNumeric

func IsNumeric(s string) bool

IsNumeric checks whether the given string s is numeric. Note that float string like "123.456" is also numeric.

func IsSlice

func IsSlice(value interface{}) bool

IsSlice checks whether `value` is type of slice.

func IsStruct

func IsStruct(value interface{}) bool

IsStruct checks whether `value` is type of struct.

func IsUint

func IsUint(value interface{}) bool

IsUint checks whether `value` is type of uint.

func MapContainsPossibleKey

func MapContainsPossibleKey(data map[string]interface{}, key string) bool

MapContainsPossibleKey checks if the given `key` is contained in given map `data`. It checks the key ignoring cases and symbols.

Note that this function might be of low performance.

func MapPossibleItemByKey

func MapPossibleItemByKey(data map[string]interface{}, key string) (foundKey string, foundValue interface{})

MapPossibleItemByKey tries to find the possible key-value pair for given key ignoring cases and symbols.

Note that this function might be of low performance.

func ParseIpRange added in v0.0.2

func ParseIpRange(cidr string) ([]string, error)

ParseIpRange 用于将以 "," 分割的多个 CIDR 范围字符串解析为 CIDR 数组。 如果一个 CIDR 范围是以 "-" 分割的两个 IP 地址,那么我们会使用 binaryToInt 和 intToIP 函数将它们转换为整数并再次转换为 CIDR 字符串, 并将其加入到 CIDR 数组中。

func ParsePrivateKeyFromPEM added in v0.0.2

func ParsePrivateKeyFromPEM(pemBytes []byte) (privateKey *rsa.PrivateKey, err error)

ParsePrivateKeyFromPEM 从 PEM 格式的字节切片中解析 RSA 私钥

func ParsePublicKeyFromPEM added in v0.0.2

func ParsePublicKeyFromPEM(pemBytes []byte) (publicKey *rsa.PublicKey, err error)

ParsePublicKeyFromPEM 从 PEM 格式的字节切片中解析 RSA 公钥

func RemoveSymbols

func RemoveSymbols(s string) string

RemoveSymbols removes all symbols from string and lefts only numbers and letters.

func Replace

func Replace(pattern string, replace, src []byte) ([]byte, error)

Replace replaces all matched `pattern` in bytes `src` with bytes `replace`.

func ReplaceByMap

func ReplaceByMap(origin string, replaces map[string]string) string

ReplaceByMap returns a copy of `origin`, which is replaced by a map in unordered way, case-sensitively.

func ReplaceString

func ReplaceString(pattern, replace, src string) (string, error)

ReplaceString replace all matched `pattern` in string `src` with string `replace`.

func ReplaceTemplate added in v0.0.2

func ReplaceTemplate(content string, variable map[string]interface{}) (result string, err error)

func SavePrivateKeyToFile added in v0.0.2

func SavePrivateKeyToFile(privateKey *rsa.PrivateKey, filename string) (err error)

SavePrivateKeyToFile 将 RSA 私钥保存到文件

func SavePublicKeyToFile added in v0.0.2

func SavePublicKeyToFile(publicKey *rsa.PublicKey, filename string) (err error)

SavePublicKeyToFile 将 RSA 公钥保存到文件

func SetDebugEnabled

func SetDebugEnabled(enabled bool)

SetDebugEnabled enables/disables the internal debug info.

func SplitAndTrim

func SplitAndTrim(str, delimiter string, characterMask ...string) []string

SplitAndTrim splits string `str` by a string `delimiter` to an array, and calls Trim to every element of this array. It ignores the elements which are empty after Trim.

func StripSlashes

func StripSlashes(str string) string

StripSlashes un-quotes a quoted string by AddSlashes.

func StructToMap

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

func Trim

func Trim(str string, characterMask ...string) string

Trim strips whitespace (or other characters) from the beginning and end of a string. The optional parameter `characterMask` specifies the additional stripped characters.

func UcFirst

func UcFirst(s string) string

UcFirst returns a copy of the string s with the first letter mapped to its upper case.

Types

This section is empty.

Directories

Path Synopsis
Package empty provides functions for checking empty/nil variables.
Package empty provides functions for checking empty/nil variables.
Package ratelimit 提供了一个灵活的令牌桶实现,用于速率限制。
Package ratelimit 提供了一个灵活的令牌桶实现,用于速率限制。
Package reflection provides some reflection functions for internal usage.
Package reflection provides some reflection functions for internal usage.
Package rwmutex provides switch of concurrent safety feature for sync.RWMutex.
Package rwmutex provides switch of concurrent safety feature for sync.RWMutex.
Package gtag providing tag content storing for struct.
Package gtag providing tag content storing for struct.

Jump to

Keyboard shortcuts

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