zstring

package
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: MIT Imports: 30 Imported by: 36

Documentation

Overview

Package zstring provides String related operations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AesDecrypt added in v1.1.20

func AesDecrypt(cipherText []byte, key string, iv ...string) (plainText []byte, err error)

AesDecrypt aes decryption

func AesDecryptString added in v1.1.20

func AesDecryptString(cipherText string, key string, iv ...string) (string,
	error)

AesDecryptString Aes Decrypt to String

func AesEncrypt added in v1.1.20

func AesEncrypt(plainText []byte, key string, iv ...string) (ciphertext []byte,
	err error)

AesEncrypt aes encryption

func AesEncryptString added in v1.1.20

func AesEncryptString(plainText string, key string, iv ...string) (string, error)

AesEncryptString Aes Encrypt to String

func AesGCMDecrypt added in v1.3.5

func AesGCMDecrypt(ciphertext []byte, key string) (plaintext []byte, err error)

func AesGCMDecryptString added in v1.3.5

func AesGCMDecryptString(cipherText string, key string) (string,
	error)

func AesGCMEncrypt added in v1.3.5

func AesGCMEncrypt(plaintext []byte, key string) (ciphertext []byte, err error)

func AesGCMEncryptString added in v1.3.5

func AesGCMEncryptString(plainText string, key string) (string, error)

func Base64Decode added in v0.1.20

func Base64Decode(data []byte) (value []byte, err error)

func Base64DecodeString added in v0.1.20

func Base64DecodeString(data string) (value string, err error)

func Base64Encode added in v0.1.20

func Base64Encode(value []byte) []byte

func Base64EncodeString added in v0.1.20

func Base64EncodeString(value string) string

func Buffer

func Buffer(size ...int) *strings.Builder

Buffer Buffer

func Bytes2String

func Bytes2String(b []byte) string

Bytes2String bytes to string

func CamelCaseToSnakeCase added in v0.0.19

func CamelCaseToSnakeCase(str string, delimiter ...string) string

CamelCaseToSnakeCase camelCase To SnakeCase helloWorld/HelloWorld => hello_world

func Expand added in v1.5.2

func Expand(s string, process func(key string) string) string

func GenRSAKey added in v1.3.5

func GenRSAKey(bits ...int) (prvkey, pubkey []byte, err error)

GenRSAKey RSA public key private key generation

func Img2Base64 added in v0.1.46

func Img2Base64(path string) (string, error)

Img2Base64 read picture files and convert to base 64 strings

func IsLcfirst added in v0.0.19

func IsLcfirst(str string) bool

IsLcfirst tests whether the given byte b is in lower case

func IsPattern added in v0.0.19

func IsPattern(str string) bool

func IsUcfirst added in v0.0.19

func IsUcfirst(str string) bool

IsUcfirst tests whether the given byte b is in upper case

func Lcfirst added in v0.0.19

func Lcfirst(str string) string

Lcfirst First letters lowercase

func Len

func Len(str string) int

Len string length (utf8)

func Match added in v0.0.19

func Match(str, pattern string) bool

func Md5 added in v0.1.20

func Md5(s string) string

func Md5Byte added in v1.2.0

func Md5Byte(s []byte) string

func Md5File added in v0.1.20

func Md5File(path string) (encrypt string, err error)

func NewFilter added in v0.1.59

func NewFilter(words []string, mask ...rune) *filterNode

func NewReplacer added in v0.1.59

func NewReplacer(mapping map[string]string) *replacer

func PKCS7Padding added in v0.1.63

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

PKCS7Padding PKCS7 fill mode

func PKCS7UnPadding added in v0.1.63

func PKCS7UnPadding(origData []byte) ([]byte, error)

PKCS7UnPadding Reverse operation of padding to delete the padding string

func Pad

func Pad(raw string, length int, padStr string, padType PadType) string

Pad String padding

func ParseID added in v0.1.35

func ParseID(id int64) (t time.Time, ts int64, workerId int64, seq int64)

ParseID reverse uid to timestamp, workid, seq

func ProjectMd5 added in v1.5.1

func ProjectMd5() string

func RSADecrypt added in v1.1.20

func RSADecrypt(cipherText []byte, privateKey string, bits ...int) ([]byte, error)

RSADecrypt RSA Decrypt

func RSADecryptString added in v1.1.20

func RSADecryptString(cipherText string, privateKey string) (string, error)

RSADecryptString RSA Decrypt to String

func RSAEncrypt added in v1.1.20

func RSAEncrypt(plainText []byte, publicKey string, bits ...int) ([]byte, error)

RSAEncrypt RSA Encrypt

func RSAEncryptString added in v1.1.20

func RSAEncryptString(plainText string, publicKey string) (string, error)

RSAEncryptString RSA Encrypt to String

func RSAKeyDecrypt added in v1.3.5

func RSAKeyDecrypt(cipherText []byte, privateKey *rsa.PrivateKey, bits ...int) ([]byte, error)

RSAKeyDecrypt RSA Decrypt

func RSAKeyEncrypt added in v1.3.5

func RSAKeyEncrypt(plainText []byte, publicKey *rsa.PublicKey, bits ...int) ([]byte, error)

RSAKeyEncrypt RSA Encrypt

func RSAPriKeyEncrypt added in v1.1.21

func RSAPriKeyEncrypt(plainText []byte, privateKey string) ([]byte, error)

RSAPriKeyEncrypt RSA PriKey Encrypt

func RSAPriKeyEncryptString added in v1.1.21

func RSAPriKeyEncryptString(plainText string, privateKey string) (string, error)

RSAPriKeyEncryptString RSA PriKey Encrypt to String

func RSAPubKeyDecrypt added in v1.1.21

func RSAPubKeyDecrypt(cipherText []byte, publicKey string) ([]byte, error)

RSAPubKeyDecrypt RSA PubKey Decrypt

func RSAPubKeyDecryptString added in v1.1.21

func RSAPubKeyDecryptString(cipherText string, publicKey string) (string,
	error)

RSAPubKeyDecryptString RSA PubKey Decrypt to String

func Rand

func Rand(n int, tpl ...string) string

Rand random string of specified length, the second parameter limit can only appear the specified character

func RandInt added in v0.0.19

func RandInt(min int, max int) int

RandInt random numbers in the specified range

func RandUint32 added in v0.1.53

func RandUint32() uint32

func RandUint32Max added in v0.1.53

func RandUint32Max(max uint32) uint32

RandUint32Max returns pseudorandom uint32 in the range [0..max)

func RegexExtract added in v0.0.19

func RegexExtract(pattern string, str string) ([]string, error)

RegexExtract extract matching text

func RegexExtractAll added in v0.1.42

func RegexExtractAll(pattern string, str string, count ...int) ([][]string, error)

RegexExtractAll extract matching all text

func RegexFind added in v0.0.19

func RegexFind(pattern string, str string, count int) [][]int

RegexFind return matching position

func RegexMatch added in v0.0.19

func RegexMatch(pattern string, str string) bool

RegexMatch check for match

func RegexReplace added in v0.0.19

func RegexReplace(pattern string, str, repl string) (string, error)

RegexReplace replacing matches of the Regexp

func RegexReplaceFunc added in v0.0.19

func RegexReplaceFunc(pattern string, str string, repl func(string) string) (string, error)

RegexReplaceFunc replacing matches of the Regexp

func RegexSplit added in v1.6.1

func RegexSplit(pattern string, str string) ([]string, error)

RegexSplit split the string

func Serialize added in v0.1.43

func Serialize(value interface{}) ([]byte, error)

func SnakeCaseToCamelCase added in v0.0.19

func SnakeCaseToCamelCase(str string, ucfirst bool, delimiter ...string) string

SnakeCaseToCamelCase snakeCase To CamelCase: hello_world => helloWorld

func String2Bytes

func String2Bytes(s string) []byte

String2Bytes string to bytes remark: read only, the structure of runtime changes will be affected, the role of unsafe.Pointer will be changed, and it will also be affected

func Substr

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

Substr returns part of a string

func TrimBOM added in v0.0.19

func TrimBOM(fileBytes []byte) []byte

TrimBOM TrimBOM

func TrimLine added in v1.4.8

func TrimLine(s string) string

TrimLine TrimLine

func TrimSpace added in v1.1.11

func TrimSpace(s string) string

TrimSpace TrimSpace

func UUID added in v0.1.28

func UUID() int64

func Ucfirst added in v0.0.19

func Ucfirst(str string) string

Ucfirst First letters capitalize

func UnSerialize added in v0.1.43

func UnSerialize(valueBytes []byte, registers ...interface{}) (value interface{}, err error)

func UniqueID added in v1.1.3

func UniqueID(n int) string

UniqueID unique id minimum 6 digits

func UrlDecode added in v0.1.20

func UrlDecode(str string) (string, error)

UrlDecode url decode string

func UrlEncode added in v0.1.20

func UrlEncode(str string) string

UrlEncode url encode string, is + not %20

func UrlRawDecode added in v0.1.20

func UrlRawDecode(str string) (string, error)

UrlRawDecode Decode URL-encoded strings.

func UrlRawEncode added in v0.1.20

func UrlRawEncode(str string) string

UrlRawEncode URL-encode according to RFC 3986.

func WeightedRand added in v1.6.4

func WeightedRand(choices map[interface{}]uint32) (interface{}, error)

func XSSClean added in v0.1.35

func XSSClean(str string) string

XSSClean clean html tag

Types

type IDWorker added in v0.1.35

type IDWorker struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

IDWorker Struct

func NewIDWorker added in v0.1.35

func NewIDWorker(workerid int64) (iw *IDWorker, err error)

NewIDWorker Generate NewIDWorker with Given workerid

func (*IDWorker) ID added in v0.1.35

func (iw *IDWorker) ID() (ts int64, err error)

ID Generate next id

type PadType added in v1.3.2

type PadType uint8
const (
	// PadRight Right padding character
	PadRight PadType = iota
	// PadLeft Left padding character
	PadLeft
	// PadSides Two-sided padding characters,If the two sides are not equal, the right side takes precedence.
	PadSides
)

type Weighteder added in v1.6.4

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

func NewWeightedRand added in v1.6.4

func NewWeightedRand(choices map[interface{}]uint32) (*Weighteder, error)

func (*Weighteder) Pick added in v1.6.4

func (w *Weighteder) Pick() interface{}

Jump to

Keyboard shortcuts

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