guidutil

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2019 License: MIT Imports: 4 Imported by: 0

README

How to use this guid generator

  1. Import the package in go script
package main
import (
	"github.com/alessandromr/GoGuid/guid"
)
  1. Simple call the package in your function
//...Function Code
   token := guidutil.CreateToken()
//...Function Code

Or use custom token format (length int, timeFormat string)

//...Function Code
   token := guidutil.CreateCustomToken(256, "20060102150405.999999")
//...Function Code

How Token is formed:

Tokens are formed with a URL safe encoding, they can be used in cookie or in URL without any problems. The token are encoded with base64 (URL Friendly).

Example Token

MjAxODEwMjUxMDM3NTkuNjM0__lRuOZxsIgkVHXC5aoebCrtYyYj-XRXiIWqjhJhZ6rMgQcin-3KDbqe8IoRnx0CVlfwrQG7TbGOPPlVHUu77s1Q==

Timestamp

Timestamp make the token sequential, before encoding timestamp is a simple datetime string:
20060102150405.999
This datetime is formed in this way: YearMonthDayHourMinuteSecond.Milliseconds Timestamp is the part of the token before the separator In example token the timestamp is:

MjAxODEwMjUxMDM3NTkuNjM0

Separator

Timestamp and random string are separeted by two underscore:
__

Random string

Random string is the part of the token after the separator In example token the random string is: lRuOZxsIgkVHXC5aoebCrtYyYj-XRXiIWqjhJhZ6rMgQcin-3KDbqe8IoRnx0CVlfwrQG7TbGOPPlVHUu77s1Q==

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateCustomToken

func CreateCustomToken(byteLen int, timeFormat string) string

func CreateToken

func CreateToken() string

Main

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomString

func GenerateRandomString(n int) (string, error)

GenerateRandomString returns a securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

Types

This section is empty.

Jump to

Keyboard shortcuts

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