boiling

package module
v0.0.0-...-870d504 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2018 License: MIT Imports: 8 Imported by: 0

README

boiling

An incremented id generator based on etcd, mainly relied on the behavior that etcd increments the version of key when any modification(put call) occured

Build Status MIT license GoDoc Go Report Card

Import

go get -u github.com/bittenApple/boiling

Usage example

First you need a etcd instance running on http://localhost:2379

package main

import (
	"fmt"
	"log"

	"github.com/bittenApple/boiling"
)

func main() {
	o := &boiling.Options{
		Endpoints: []string{"http://localhost:2379"},
	}
	cli, err := boiling.NewClient(o)
	if err != nil {
		log.Printf("boiling client failed")
		return
	}
	fmt.Println(cli.GetId())
}

Documentation

Overview

Package boiling provides function to generate incremented id based on etcd

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client provides and manages an boiling client

func NewClient

func NewClient(opt *Options) (*Client, error)

NewClient returns a client which generates incremented id.

func (*Client) GetId

func (c *Client) GetId() int64

GetId returns the generated id in sequence

func (*Client) Reset

func (c *Client) Reset() error

Reset deletes the corresponding etcd key, resets the id to start value

func (*Client) Stop

func (c *Client) Stop()

Stop stops generating id, and getId() function will always return 0

type Options

type Options struct {
	Key       string   // the key name in etcd
	Buffer    int64    // the buffered ids interactive once with etcd
	Start     int64    // the start value of id sequences,which will be ignored if the value already be set,
	Endpoints []string // etcd endpoints
	Initial   bool     // Whether restart from start value
}

Options configures how we set up the client.

Jump to

Keyboard shortcuts

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