Coder Social home page Coder Social logo

nexus's Introduction

Nexus

Introduction

This is a package for generating unique IDs in a distributed environment. It is based on Twitter's Snowflake algorithm, which has a theoretical maximum of 174 unique IDs, and offers excellent performance. The package is implemented in Go programming language version 1.19.

Features

  • Generates unique IDs in a distributed environment
  • Based on Twitter's Snowflake algorithm
  • Theoretical maximum of 174 years unique IDs
  • Excellent performance
  • Written in Go programming language version 1.19

Usage

Installation

To install the package, run the following command in your terminal:

go get github.com/atopx/nexus@latest

Example

package main

import (
	"sync"
	"testing"
	"time"

	"github.com/atopx/nexus"
)

func main() {
	n := nexus.NewNexus(nexus.WithStartTime(time.Now()))
	wg := new(sync.WaitGroup)
	for i := 0; i < 20; i++ {
		go func(n *nexus.Nexus, wg *sync.WaitGroup) {
            wg.Add(1)
			part, _ := n.NextId()
			defer n.Recover(part)
			t.Logf("nexus part: %+v", part)
			wg.Done()
		}(n, wg)
	}
	wg.Wait()
}

Contributions

We welcome contributions from the community. If you find a bug or have a feature request, please open an issue. If you would like to contribute code, please create a pull request.

License

This package is released under the MIT License.

nexus's People

Contributors

atopx avatar atop-code avatar

Stargazers

小二 avatar  avatar

Watchers

 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.