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: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
⌂ 换网址