randx

package
v0.0.9 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// TypeDigit 数字
	TypeDigit Type = 1
	// TypeLowerCase 小写字母
	TypeLowerCase Type = 1 << 1
	// TypeUpperCase 大写字母
	TypeUpperCase Type = 1 << 2
	// TypeSpecial 特殊符号
	TypeSpecial Type = 1 << 3
	// TypeMixed 混合类型
	TypeMixed = (TypeDigit | TypeUpperCase | TypeLowerCase | TypeSpecial)

	// CharsetDigit 数字字符组
	CharsetDigit = "0123456789"
	// CharsetLowerCase 小写字母字符组
	CharsetLowerCase = "abcdefghijklmnopqrstuvwxyz"
	// CharsetUpperCase 大写字母字符组
	CharsetUpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	// CharsetSpecial 特殊字符数组
	CharsetSpecial = " ~!@#$%^&*()_+-=[]{};'\\:\"|,./<>?"
)

Variables

This section is empty.

Functions

func RandCode

func RandCode(length int, typ Type) (string, error)

RandCode 根据传入的长度和类型生成随机字符串 请保证输入的 length >= 0,否则会返回 errLengthLessThanZero 请保证输入的 typ 的取值范围在 (0, type.MIXED] 内,否则会返回 errTypeNotSupported

func RandStrByCharset added in v0.0.9

func RandStrByCharset(length int, charset string) (string, error)

RandStrByCharset 根据传入的长度和字符集生成随机字符串 请保证输入的 length >= 0,否则会返回 errLengthLessThanZero 请保证输入的字符集不为空字符串,否则会返回 errTypeNotSupported 字符集内部字符可以无序或重复

Types

type Type added in v0.0.9

type Type int

Jump to

Keyboard shortcuts

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