Giter Club home page Giter Club logo

go-tinyid's Introduction

go-tinyid

Go Report Card

ID Generator id生成器 分布式id生成系统,简单易用、高性能、高可用的id生成系统

fork from https://github.com/didi/tinyid (golang version)

Server

./server/build.sh

package main

import (
	"github/rrylee/go-tinyid/internal"
	"github/rrylee/go-tinyid/server/http"
	"log"
	"os"
)

func main() {
	internal.Logger = log.New(os.Stdout, "[tiny-id]", 0) // your logger component
	err := http.Run("/Users/rry/Code/github/go-tinyid/server")
	if err != nil {
		panic(err)
	}
}

client 接入

package main

import (
	"github/rrylee/go-tinyid/internal"
	"github/rrylee/go-tinyid/client"
	"github/rrylee/go-tinyid/client/config"
	"log"
	"os"
)

func main() {
	internal.Logger = log.New(os.Stdout, "[test]", 0)
	client.Init(&config.Config{
		TinyIdServer: []string{"http://127.0.0.1:8999"},
		TinyIdToken:  "test",
		Timeout:      1 * time.Second,
	})

	client := &client.TinyIdClient{}
	for i := 0; i < 100; i++ {
		fmt.Println(client.NextId("test"))
	}
}

http 接入

$curl http://localhost:8999/tinyid/id/nextId?bizType=test&batchSize=10
${
    "Data": [
        1900091,
        1900092,
        1900093,
        1900094,
        1900095,
        1900096,
        1900097,
        1900098,
        1900099,
        1900100
    ],
    "Code": 200,
    "Message": ""
}

$ curl http://localhost:8999/tinyid/id/nextIdSimple?bizType=test&batchSize=10
$ 1900101,1900102,1900103,1900104,1900105,1900106,1900107,1900108,1900109,1900110

go-tinyid's People

Contributors

sword-jin avatar

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.