http

package
v3.12.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2017 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package http provides the HTTP server for accessing the distributed database. It also provides the endpoint for other nodes to join an existing cluster.

Index

Constants

View Source
const (

	// PermAll means all actions permitted.
	PermAll = "all"
	// PermJoin means user is permitted to join cluster.
	PermJoin = "join"
	// PermRemove means user is permitted to remove a node.
	PermRemove = "remove"
	// PermExecute means user can access execute endpoint.
	PermExecute = "execute"
	// PermQuery means user can access query endpoint
	PermQuery = "query"
	// PermStatus means user can retrieve node status.
	PermStatus = "status"
	// PermBackup means user can backup node.
	PermBackup = "backup"
	// PermLoad means user can load a SQLite dump into a node.
	PermLoad = "load"

	// VersionHTTPHeader is the HTTP header key for the version.
	VersionHTTPHeader = "X-RQLITE-VERSION"
)

Variables

This section is empty.

Functions

func NormalizeAddr

func NormalizeAddr(addr string) string

NormalizeAddr ensures that the given URL has a HTTP protocol prefix. If none is supplied, it prefixes the URL with "http://".

Types

type CredentialStore

type CredentialStore interface {
	// Check returns whether username and password are a valid combination.
	Check(username, password string) bool

	// HasPerm returns whether username has the given perm.
	HasPerm(username string, perm string) bool
}

CredentialStore is the interface credential stores must support.

type Response

type Response struct {
	Results interface{} `json:"results,omitempty"`
	Error   string      `json:"error,omitempty"`
	Time    float64     `json:"time,omitempty"`
	// contains filtered or unexported fields
}

Response represents a response from the HTTP service.

func NewResponse

func NewResponse() *Response

NewResponse returns a new instance of response.

func (*Response) SetTime

func (r *Response) SetTime()

SetTime sets the Time attribute of the response. This way it will be present in the serialized JSON version.

type Service

type Service struct {
	CertFile string // Path to SSL certificate.
	KeyFile  string // Path to SSL private key.

	Expvar bool
	Pprof  bool

	BuildInfo map[string]interface{}
	// contains filtered or unexported fields
}

Service provides HTTP service.

func New

func New(addr string, store Store, credentials CredentialStore) *Service

New returns an uninitialized HTTP service. If credentials is nil, then the service performs no authentication and authorization checks.

func (*Service) Addr

func (s *Service) Addr() net.Addr

Addr returns the address on which the Service is listening

func (*Service) CheckRequestPerm

func (s *Service) CheckRequestPerm(r *http.Request, perm string) bool

CheckRequestPerm returns true if authentication is enabled and the user contained in the BasicAuth request has either PermAll, or the given perm.

func (*Service) Close

func (s *Service) Close()

Close closes the service.

func (*Service) FormRedirect

func (s *Service) FormRedirect(r *http.Request, host string) string

FormRedirect returns the value for the "Location" header for a 301 response.

func (*Service) ServeHTTP

func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP allows Service to serve HTTP requests.

func (*Service) Start

func (s *Service) Start() error

Start starts the service.

type Store

type Store interface {
	// Execute executes a slice of queries, each of which is not expected
	// to return rows. If timings is true, then timing information will
	// be return. If tx is true, then either all queries will be executed
	// successfully or it will as though none executed.
	Execute(queries []string, timings, tx bool) ([]*sql.Result, error)

	// Query executes a slice of queries, each of which returns rows. If
	// timings is true, then timing information will be returned. If tx
	// is true, then all queries will take place while a read transaction
	// is held on the database.
	Query(queries []string, timings, tx bool, lvl store.ConsistencyLevel) ([]*sql.Rows, error)

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

	// Remove removes the node, specified by addr, from the cluster.
	Remove(addr string) error

	// Leader returns the Raft leader of the cluster.
	Leader() string

	// Peer returns the API peer for the given address
	Peer(addr string) string

	// Stats returns stats on the Store.
	Stats() (map[string]interface{}, error)

	// Backup returns a byte slice representing a backup of the node state.
	Backup(leader bool) ([]byte, error)
}

Store is the interface the Raft-based database must implement.

Jump to

Keyboard shortcuts

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