Coder Social home page Coder Social logo

go-idpot's Introduction

go-idpot

Build Status

Layman's idpot (Serial ID Generator) Using Mysql

Description

This is a dead simple implementation of an "idpot", a server that generates serial 64-bit unsigned integer IDs. It uses MySQL's MyISAM db and LAST_INSERT_ID functionality as the basis to generate an ID, along with a dead simple HTTP API.

Why/When Would you use this? It's easy to create a 64 bit UID generator without using MySQL, but it's also really hard to make sure that the ID generation is fast + correct, AND also make it not go ga-ga. MySQL is, even if you don't like it as a DB, battlefield-tested server with just enough speed and stability. Sometimes it's easier just to slap an easy to use API over what's already available :)

Once you start the server, you can create a "pot" by POST-ing to

  http://youserver/pot/create

With parameters like:

  name: NameOfYourPot
  min: MinimumIntValue

Of course, you can do this by hand in your MySQL server, but it's just there for convenience. Note: Obviously, you should NOT expose this to the outside world.

You can verify that this pot has been actually created by issuing a GET request:

  http://yourserver/pot/NameOfYourPot

This will return a 204 if the pot exists, 404 otherwise.

After that, all you need to do is to issue POST requests to

  http://yourserver/id/NameOfYourPot

and a text/plain response with just the ID in its body will be returned, which you can be sure that it will not be generated again from that same pot (as long as you don't manually muck with the backend DB)

If you just want to get the current value (which can only be needed for admin purposes), then you can issue a GET request to the same URL, and you will get the current ID, and it won't be automatically incremented

Building/Installing

Just install the server binary:

  go install cli/idpot-server/idpot-server.go

Or build it manually:

  go build -o idpot-server cli/idpot-server/idpot-server.go

Using idpot-server

  $ idpot-server --config=/path/to/config.gcfg

The config file must at least specify the necessary information to connect to a MySQL server

[Server]
LogFile = /path/to/access_log-%Y%m%d
LogLinkName = /path/to/access_log

[Mysql]
ConnectString = user:password@tcp(host:port)/dbname

go-idpot's People

Contributors

lestrrat avatar

Watchers

James Cloos avatar  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.