http

package
v0.0.0-...-854fb4c Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: MIT Imports: 18 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 (

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

Variables

View Source
var (
	// ErrNoStatements is returned when a request is empty
	ErrNoStatements = errors.New("no statements")

	// ErrInvalidRequest is returned when a request cannot be parsed.
	ErrInvalidRequest = errors.New("invalid request")

	// ErrUnsupportedType is returned when a request contains an unsupported type.
	ErrUnsupportedType = errors.New("unsupported type")
)

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://".

func ParseRequest

func ParseRequest(b []byte) ([]*command.Statement, error)

ParseRequest generates a set of Statements for a given byte slice.

Types

type Cluster

type Cluster interface {
	// GetNodeAPIAddr returns the HTTP API URL for the node at the given Raft address.
	GetNodeAPIAddr(nodeAddr string) (string, error)

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

Cluster is the interface node API services must provide

type Database

type Database 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(er *command.ExecuteRequest) ([]*sql.Result, error)

	// ExecuteOrAbort performs the same function as Execute(), but ensures
	// any transactions are aborted in case of any error.
	ExecuteOrAbort(er *command.ExecuteRequest) ([]*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(qr *command.QueryRequest) ([]*sql.Rows, error)
}

Database is the interface any queryable system must implement

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 {
	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, cluster Cluster) *Service

New returns an uninitialized HTTP service.

func (*Service) Addr

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

Addr returns the address on which the Service is listening

func (*Service) Close

func (s *Service) Close()

Close closes the service.

func (*Service) FormRedirect

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

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

func (*Service) LeaderAPIAddr

func (s *Service) LeaderAPIAddr() string

LeaderAPIAddr returns the API address of the leader, as known by this node.

func (*Service) RegisterStatus

func (s *Service) RegisterStatus(key string, stat Statuser) error

RegisterStatus allows other modules to register status for serving over HTTP.

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 Statuser

type Statuser interface {
	Stats() (interface{}, error)
}

Statuser is the interface status providers must implement.

type Store

type Store interface {
	Database

	// Join joins the node with the given ID, reachable at addr, to this node.
	Join(id, addr string, voter bool) error

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

	// LeaderAddr returns the Raft address of the leader of the cluster.
	LeaderAddr() (string, error)

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

	// Nodes returns the slice of store.Servers in the cluster
	Nodes() ([]*store.Server, error)

	// Backup wites backup of the node state to dst
	Backup(leader bool, f store.BackupFormat, dst io.Writer) 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