All Projects → marksalpeter → token

marksalpeter / token

Licence: MIT license
A simple base62 encoded token library for go, ideal for short url services.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to token

urlpack
Pure JavaScript toolkit for data URLs (MessagePack, Base58 and Base62)
Stars: ✭ 51 (-25%)
Mutual labels:  encoder, base62
Balance-Bot
A two-wheel self-balancing robot based on the ATmega2560 micro-controller.
Stars: ✭ 33 (-51.47%)
Mutual labels:  encoder
friendly-id
Java Friendly Id for UUID
Stars: ✭ 173 (+154.41%)
Mutual labels:  base62
PCF8574 library
i2c digital expander for Arduino, esp32, SMT32 and ESP8266. Can read write digital values with only 2 wire. Very simple to use and encoder support.
Stars: ✭ 145 (+113.24%)
Mutual labels:  encoder
gocnab
CNAB (Un)Marshaler
Stars: ✭ 20 (-70.59%)
Mutual labels:  encoder
bytecodec
A tiny Rust framework for implementing encoders/decoders of byte-oriented protocols
Stars: ✭ 21 (-69.12%)
Mutual labels:  encoder
video-quality-metrics
Test specified presets/CRF values for the x264 or x265 encoder. Compares VMAF/SSIM/PSNR numerically & via graphs.
Stars: ✭ 87 (+27.94%)
Mutual labels:  encoder
Transcoder
Docker container to transcode videos in mounted volume to H265 using FFMPEG
Stars: ✭ 13 (-80.88%)
Mutual labels:  encoder
png pong
A pure Rust PNG image decoder and encoder based on lodepng.
Stars: ✭ 21 (-69.12%)
Mutual labels:  encoder
nanopack
Lightweight Msgpack Encoder
Stars: ✭ 15 (-77.94%)
Mutual labels:  encoder
USB-Rubber-Ducky-App
🐣 Windows GUI for USB Rubber Ducky
Stars: ✭ 63 (-7.35%)
Mutual labels:  encoder
logfmt
Package logfmt marshals and unmarshals logfmt messages.
Stars: ✭ 156 (+129.41%)
Mutual labels:  encoder
QTFiles
use qaac without installing iTunes
Stars: ✭ 76 (+11.76%)
Mutual labels:  encoder
sms
A Go library for encoding and decoding SMSs
Stars: ✭ 37 (-45.59%)
Mutual labels:  encoder
png
🖼A full-featured PNG decoder and encoder.
Stars: ✭ 64 (-5.88%)
Mutual labels:  encoder
badchars
Bad char generator to instruct encoders such as shikata-ga-nai to transform those to other chars.
Stars: ✭ 178 (+161.76%)
Mutual labels:  encoder
VIDEOconvertor
A stable and Fast telegram video convertor bot which can encode into different libs and resolution, compress videos, convert video into audio and other video formats, rename with thumbnail support, generate screenshot and trim videos.
Stars: ✭ 180 (+164.71%)
Mutual labels:  encoder
EncoderTool
The EncoderTool is a library to manage and read out rotary encoders connected either directly or via multiplexers to ARM based boards. Encoder push buttons are supported. Callback functions can be attached to encoder changes and button presses to allow for event driven applications
Stars: ✭ 29 (-57.35%)
Mutual labels:  encoder
xin26x
Video Encoder for Now and Next Decade
Stars: ✭ 74 (+8.82%)
Mutual labels:  encoder
gogif
The (no longer) missing GIF encoder for #golang
Stars: ✭ 21 (-69.12%)
Mutual labels:  encoder

Use v2 Instead

Warning: Breaking Changes

Version 2 of this package is ready for production use. You can find it here.

The order of the Base62 characters have been changed in v2 so that the string representation of the Token and the int representation of the token are in the same sort order. This is useful when scaling your app or using NoSQL solutions. Special thanks to @sudhirj for the suggestion.

References

https://instagram-engineering.com/sharding-ids-at-instagram-1cf5a71e5a5c

https://developer.twitter.com/en/docs/basics/twitter-ids.html

https://github.com/ulid/spec


GoDoc

This is a simple package for go that generates randomized base62 encoded tokens based on an integer. It's ideal for short url services or for any short, unique, randomized tokens you need to use throughout your app.

How it Works

Token is an alias for uint64.

The Token.Encode() method returns a base62 encoded string based off of the uint64.

Token implements the encoding.TextMarshaler and encoding.TextUnmarshaler interfaces to encode and decode to and from the base62 string representation of the uint64

Basically, the outside world will always see the token as a base62 encoded string, but in your app you will always be able to use the token as a uint64 for fast, indexed, unique, lookups in various databases.

IMPORTANT: Remember to always check for collisions when adding randomized tokens to a database

Example

package main

import (
	"fmt"
	"github.com/marksalpeter/token"
)

type Model struct {
    ID	token.Token `json:"id"`
}

func main() {
	// create a new model
	model := Model {
		ID:	token.New(), // creates a new, random uint64 token
	}
	fmt.Println(model.ID)          // 2751173559858
	fmt.Println(model.ID.Encode()) // Mr1NSSu

	// encode the model as json
	marshaled, err := json.Marshal(&model)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(marshaled)) // {"id":"Mr1NSSu"}

	// decode the model
	var unmarshaled Model
	if err := json.Unmarshal(marshaled, &unmarshaled); err != nil {
		panic(err)
	}
	fmt.Println(unmarshaled.ID)    // 2751173559858

}

Special Mentions

Special thanks to @einsteinx2. The encode and decode functions are ported from a short url project of his and he graciously allowed me to publish them.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].