str

package
v0.0.7 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: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func B

func B(n int) []byte

B retrieves and returns random bytes of given length `n`.

func D

func D(min, max time.Duration) time.Duration

D returns a random time.Duration between min and max: [min, max].

func Digits

func Digits(n int) string

Digits returns a random str which contains only digits, and its length is `n`.

func Intn

func Intn(max int) int

func Letters

func Letters(n int) string

Letters returns a random str which contains only letters, and its length is `n`.

func Meet

func Meet(num, total int) bool

Meet randomly calculate whether the given probability `num`/`total` is met.

func MeetProb

func MeetProb(prob float32) bool

MeetProb randomly calculate whether the given probability is met.

func N

func N(min, max int) int

N returns a random int between min and max: [min, max]. The `min` and `max` also support negative numbers.

func PadLeftZeros

func PadLeftZeros(str string, length int) string

PadLeftZeros 前置补零

func Perm

func Perm(n int) []int

Perm returns, as a slice of n int numbers, a pseudo-random permutation of the integers [0,n). TODO performance improving for large slice producing.

func S

func S(n int, symbols ...bool) string

S returns a random str which contains digits and letters, and its length is `n`. The optional parameter `symbols` specifies whether the result could contain symbols, which is false in default.

func Str

func Str(s string, n int) string

Str randomly picks and returns `n` count of chars from given str `s`. It also supports unicode str like Chinese/Russian/Japanese, etc.

func Symbols

func Symbols(n int) string

Symbols returns a random str which contains only symbols, and its length is `n`.

Types

type Secret

type Secret struct{}

func (Secret) Decode

func (Secret) Decode(data []byte) ([]byte, error)

func (Secret) DecryptAuthorization

func (Secret) DecryptAuthorization(token, secretKey string, iv []byte) (DecryptStr, uuid string, err error)

func (Secret) DecryptCBC

func (Secret) DecryptCBC(cipherText, key, iv []byte, ivs ...[]byte) ([]byte, error)

func (Secret) Encode

func (Secret) Encode(src []byte) []byte

func (Secret) Encrypt

func (Secret) Encrypt(data any) (encrypt string, err error)

func (Secret) EncryptBytes

func (Secret) EncryptBytes(data []byte) (encrypt string, err error)

func (Secret) EncryptCBC

func (Secret) EncryptCBC(plainText, key, iv []byte, ivs ...[]byte) ([]byte, error)

func (Secret) EncryptToken

func (Secret) EncryptToken(key, secretKey string, iv []byte, randStr ...string) (encryptStr, uuid string, err error)

func (Secret) MustEncrypt

func (Secret) MustEncrypt(data any) string

func (Secret) PKCS7Padding

func (Secret) PKCS7Padding(src []byte, blockSize int) []byte

func (Secret) PKCS7UnPadding

func (Secret) PKCS7UnPadding(src []byte, blockSize int) ([]byte, error)

Jump to

Keyboard shortcuts

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