service

package
v0.0.0-...-bc5e729 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2017 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package service provides the HTTP server for accessing the distributed key-value store. It also provides the endpoint for other nodes to join an existing cluster.

Index

Constants

View Source
const (
	// OK for successful response
	OK = 1000
	// ParamsError for params error response
	ParamsError = 1001
	// KeyNotFound for key/value no found response
	KeyNotFound = 1002
	// KeyDuplicate for key/value duplicate response
	KeyDuplicate = 1003
	// InternalError for internal error
	InternalError = 1004
	// NotLeaderError for not leader error
	NotLeaderError = 1005
)

Variables

View Source
var StatusInternalError = Status{
	Code:    InternalError,
	Message: "internal error",
}

StatusInternalError for internal error

View Source
var StatusKeyDuplicate = Status{
	Code:    KeyDuplicate,
	Message: "key duplicate",
}

StatusKeyDuplicate for key/value duplicate status

View Source
var StatusKeyNotFound = Status{
	Code:    KeyNotFound,
	Message: "key not found",
}

StatusKeyNotFound for key/value no found status

View Source
var StatusNotLeaderError = Status{
	Code:    NotLeaderError,
	Message: "i am not the leader",
}

StatusNotLeaderError for params error status

View Source
var StatusOK = Status{
	Code:    OK,
	Message: "",
}

StatusOK for successful status

View Source
var StatusParamsError = Status{
	Code:    ParamsError,
	Message: "params error",
}

StatusParamsError for params error status

Functions

This section is empty.

Types

type Service

type Service struct {

	//http server
	*gin.Engine
	// contains filtered or unexported fields
}

Service provides HTTP service.

func New

func New(httpAddr string, raftAddr string, storeDir string) *Service

New returns an uninitialized HTTP service.

func (*Service) Start

func (s *Service) Start()

Start starts the service.

type Status

type Status struct {
	Code    int
	Message string
}

Status for response

type Store

type Store interface {
	// Open opens a store in a single mode or not
	Open(singleMode bool) error

	// Get returns the value for the given key.
	Get(key string) (string, error)

	// Add adds key/value, via distributed consensus.
	Add(key, value string) error

	// Join joins the node, reachable at addr, to the cluster.
	Join(addr string) error

	// Peers returns the store peers
	Peers() ([]string, error)

	// Leader returns the leader address
	Leader() string

	// Stats return the stats as a map[string]string
	Stats() map[string]string
}

Store is the interface Raft-backed key-value stores must implement.

Jump to

Keyboard shortcuts

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