randid

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2022 License: MIT Imports: 3 Imported by: 1

README

randid

GoDoc Build Status Coverage Status

generate (crypto-secure) random (alphanumeric string) ids - in Go

FEATURES:

  • secure 🔒 crypto random ids thanks to crypto/rand
  • fast
  • both fixed and arbitrary long generation methods
  • tested
  • dependency-less

USAGE:

download the package

go get github.com/damdo/randid

import and use the package

import (
  "fmt"
  "github.com/damdo/randid"
)

func foo(){

    // generate a default len (32 char) id
    your32CharLongID, err := randid.ID()
    // -> 26e99c11f0a31ec57924c8e2a0712cd3
    if err != nil {
      fmt.Println(err)
    }

    // or
    desiredLen := 64
    your64CharLongID, err := randid.SizedID(desiredLen)
    // -> 6cc77090ff64c232613574bb562510f78d88a84e8351f3a68ac1caa902750bb7
    if err != nil {
      fmt.Println(err)
    }

    // change randid default len
    // every id generated from now on with .ID() will be 33 char long
    randid.DefaultLen = 33

    your33CharLongID, err := randid.ID()
    // -> 091015d5146b6d2e3f77ff50d805cee50
    if err != nil {
      fmt.Println(err)
    }

}

CREDITS:

Credits goes to https://github.com/moby/moby/blob/master/pkg/stringid
upon which this mini package is heavily based.

LICENSE:

The MIT License (MIT) - see LICENSE.md for more details

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLen = 32

DefaultLen is the default id length

Functions

func ID

func ID() (string, error)

ID generates an "defaultLen" long id

func SizedID

func SizedID(size int) (string, error)

SizedID generates an "size" long id

Types

This section is empty.

Jump to

Keyboard shortcuts

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