memfile

package
v0.0.0-...-24ca9bf Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2022 License: MIT, MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StdLen is a standard length of uniuri string to achieve ~95 bits of entropy.
	StdLen = 16
	// UUIDLen is a length of uniuri string to achive ~119 bits of entropy, closest
	// to what can be losslessly converted to UUIDv4 (122 bits).
	UUIDLen = 20
)

Variables

View Source
var (
	MRand = NewRand()
)
View Source
var StdChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")

StdChars is a set of standard characters allowed in uniuri string.

Functions

func CreateRandomString

func CreateRandomString(len int) string

func GenerateCertificateNumber

func GenerateCertificateNumber() string

func New

func New() string

New returns a new random string of the standard length, consisting of standard characters.

func NewLen

func NewLen(length int) string

NewLen returns a new random string of the provided length, consisting of standard characters.

func NewLenChars

func NewLenChars(length int, chars []byte) string

NewLenChars returns a new random string of the provided length, consisting of the provided byte slice of allowed characters (maximum 256).

func RandAsciiBytes

func RandAsciiBytes(n int) []byte

A helper function create and fill a slice of length n with characters from a-zA-Z0-9_-. It panics if there are any problems getting random bytes.

func RandStr

func RandStr(n int) (str string)

RandStr is from a later answer in the SO post.

func RandStr2

func RandStr2(ln int) string

RandStr 返回指定长度的随机字符串

func RandStringRunes3

func RandStringRunes3(n int) string

func SecureRandomAlphaString

func SecureRandomAlphaString(length int) string

func SecureRandomBytes

func SecureRandomBytes(length int) []byte

SecureRandomBytes returns the requested number of bytes using crypto/rand

func SecureRandomString

func SecureRandomString(availableCharBytes string, length int) string

SecureRandomString returns a string of the requested length, made from the byte characters provided (only ASCII allowed). Uses crypto/rand for security. Will panic if len(availableCharBytes) > 256.

Types

type MemFile

type MemFile interface {
	fmt.Stringer
	io.ReadWriteCloser
}

func NewMemFile

func NewMemFile(filename string) (MemFile, error)

NewMemFile returns an interface to an in-memory implementation of the file named filename.

The MemFile implements io.ReadWriteCloser Closing the MemFile destroys the MemFile and frees any memory allocated.

If the file does not exist or is not readable, an error is returned.

type Rand

type Rand struct {
	Seed int64
	Pool *sync.Pool
}

Doesn't share the rand library globally, reducing lock contention

func NewRand

func NewRand() *Rand

init random number generator

func (*Rand) Intn

func (s *Rand) Intn(n int) int

get a random number

func (*Rand) Read

func (s *Rand) Read(p []byte) (int, error)

bulk get random numbers

Jump to

Keyboard shortcuts

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