Giter Site home page Giter Site logo

pksuid's Introduction

PKSUID - KSUID with arbitrary string prefix

PKSUID is a small extension of the KSUID (K-Sortable Globally Unique IDs) https://github.com/segmentio/ksuid which allows prefixing KSUID with the 16 bytes arbitrary string to achieve the following kind of the identifiers:

user:208AocW9380pRVFbQ6sj6Oofu0w
product:208BJB4ntOzehBIADBW6h69juir
anything208BLsTohQ0OnynbQxoeyoRu086

Stripe uses this kind of identifier.

Why using the prefix?

The prefix part might carry additional information valuable for an application. For example the one can indicate the polymorphic relationship of a resource using an identifier with a prefix.

If you don't need prefixes, we strongly recommend using KSUID

Example

	userPrefix := pksuid.Prefix{'u', 's', 'e', 'r', ':'}
	id := pksuid.New(userPrefix)

	fmt.Println(id)
	// prints something like this: user:208ETB1zVhm50luzEgNAnLRNQZE

	id2, _ := pksuid.Parse("user:208ETB1zVhm50luzEgNAnLRNQZE")
	fmt.Println(id2.Prefix())
	fmt.Println(id2.Prefix() == userPrefix)
	fmt.Println(id2.ID())
	// user:208Np9GX0sC0J42peUKj4nW1CW9
	// user:
	// true
	// 208ETB1zVhm50luzEgNAnLRNQZE

pksuid's People

Contributors

alex-poliushkin avatar

Stargazers

Goncharov Leonid avatar Sasha Kukareko (Velmie) avatar

Watchers

 avatar Sasha Kukareko avatar  avatar  avatar

pksuid's Issues

node.js

This is fantastic! Would love to have it in node.js

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.