id

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2018 License: Apache-2.0 Imports: 1 Imported by: 1

README

Another Memory ID

Go Report Card Go Doc Coveralls github Release license

This library contains interface and set of implementations for generating different identifiers. There are multiple implementations available. For production usage identifiers must be mostly unique. For testing purposes it's often much easier to use mocked generator so it will generate the same id each time.

Table of Contents

Getting Started

Prerequisites

The project is tested with go 1.9 but probably will work with earlier versions.

Installing

Simple go get it

go get github.com/anothermemory/id
See it in action
Mocked ID for testing
package id_test

import (
    "fmt"
    "github.com/anothermemory/id"
)

func Example() {
    g := id.NewMock("123")

    fmt.Println(g.Generate())
    fmt.Println(g.Generate())

    // Output:
    // 123
    // 123
}
Real ID for production
package id_test

import (
    "fmt"
    "github.com/anothermemory/id"
)

func Example() {
    g := id.NewUUID()

    fmt.Println(g.Generate())
    fmt.Println(g.Generate())

    // Output:
    // 2118679c-d6f6-4848-8084-aaab790fd1ae
    // 394d79cb-803f-4807-a9bc-00d84d5f9ad3
}

Built With

  • dep - The dependency management tool for Go

Contributing

Please read CODE_OF_CONDUCT.md for details on our code of conduct, and CONTRIBUTING.md for details on the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Vyacheslav Enis

See also the list of contributors who participated in this project.

License

This project is licensed under the Apache License 2.0 - see the LICENSE.md file for details

Documentation

Overview

Package id contains interface and set of implementations for generating different identifiers. For production usage identifiers must be mostly unique. For testing purposes it's often much easier to use mocked generator so it will generate the same id each time.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

type Generator interface {
	// Generate returns new generated ID as string
	Generate() string
}

Generator represents interface which can be used to generate random ID values. Actual generated values depends on used implementation

func NewMock

func NewMock(value string) Generator

NewMock returns Generator which will always return passed value.

Example
package main

import (
	"fmt"

	"github.com/anothermemory/id"
)

func main() {
	g := id.NewMock("123")
	fmt.Println(g.Generate())
}
Output:

123

func NewUUID

func NewUUID() Generator

NewUUID returns Generator which will return new UUID V4 as generated values.

Example
package main

import (
	"fmt"

	"github.com/anothermemory/id"
)

func main() {
	g := id.NewUUID()
	fmt.Println(g.Generate())
}
Output:

Jump to

Keyboard shortcuts

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