Giter Site home page Giter Site logo

dchest / uniuri Goto Github PK

View Code? Open in Web Editor NEW
441.0 8.0 44.0 30 KB

Go package uniuri generates random strings good for use in URIs to identify unique objects.

License: Creative Commons Zero v1.0 Universal

Go 100.00%
random random-string uuid golang secure

uniuri's Introduction

Package uniuri

import "github.com/dchest/uniuri"

Package uniuri generates random strings good for use in URIs to identify unique objects.

Example usage:

s := uniuri.New() // s is now "apHCJBl7L1OmC57n"

A standard string created by New() is 16 bytes in length and consists of Latin upper and lowercase letters, and numbers (from the set of 62 allowed characters), which means that it has ~95 bits of entropy. To get more entropy, you can use NewLen(UUIDLen), which returns 20-byte string, giving ~119 bits of entropy, or any other desired length.

Functions read from crypto/rand random source, and panic if they fail to read from it.

Constants

const (
	// StdLen is a standard length of uniuri string to achive ~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

var StdChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")

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

Functions

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).

Public domain dedication

Written in 2011-2014 by Dmitry Chestnykh

The author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. Distributed without any warranty. http://creativecommons.org/publicdomain/zero/1.0/

uniuri's People

Contributors

argusdusty avatar dchest avatar hiendaovinh avatar morhekil avatar wellle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uniuri's Issues

Add license

Could you please add a license under which "uniuri" is being distributed?

Shouldn't panic

As a third party library, you shouldn't invoke panic() but return an error and let the client deal with the error.

Add functions returning bytes

Hi, I want to avoid unnecessary memory allocation when using the library.
Would you mind break NewLenChars into another function retuning []byte?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.