jsonhashids

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2022 License: MIT Imports: 5 Imported by: 0

README

json-hashids

A json iterator extension that marshal integer to short unique id

Usage

100% compatibility with standard lib

Replace

import "encoding/json"

json.Marshal(&data)
json.Unmarshal(input, &data)

with

import "github.com/liamylian/jsonhashids"

var json = NewConfigWithHashIDs("abcdefg", 10)

json.Marshal(&data)
json.Unmarshal(input, &data)

Example

package main

import(
	"fmt"
	"github.com/liamylian/json-hashids"
	"time"
)

var json = jsonhashids.NewConfigWithHashIDs("abcdefg", 10)

type Book struct {
	Id    int    `json:"id" hashids:"true"`
	Name  string `json:"name"`
}

func main() {
	book := Book {
		Id:          1,
		Name:        "Jane Eyre",
	}
	
	bytes, _ := json.Marshal(book)
	
	// output: {"id":"gYEL5rKBnd","name":"Jane Eyre"}
	fmt.Printf("%s", bytes)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotInteger = errors.New("not integer")

Functions

func NewConfigWithHashIDs

func NewConfigWithHashIDs(salt string, minLength int) jsoniter.API

Types

type HashIDsExtension

type HashIDsExtension struct {
	jsoniter.DummyExtension
	// contains filtered or unexported fields
}

func NewHashIDsExtension

func NewHashIDsExtension(salt string, minLength int) *HashIDsExtension

func (*HashIDsExtension) UpdateStructDescriptor

func (extension *HashIDsExtension) UpdateStructDescriptor(structDescriptor *jsoniter.StructDescriptor)

Jump to

Keyboard shortcuts

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