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
- Variables
- func CheckHTTPS(addr string) bool
- func EnsureHTTPS(addr string) string
- func NormalizeAddr(addr string) string
- func ParseRequest(b []byte) ([]*command.Statement, error)
- type CredentialStore
- type Database
- type Response
- type Service
- func (s *Service) Addr() net.Addr
- func (s *Service) CheckRequestPerm(r *http.Request, perm string) (b bool)
- func (s *Service) Close()
- func (s *Service) FormRedirect(r *http.Request, protocol, host string) string
- func (s *Service) LeaderAPIAddr() string
- func (s *Service) LeaderAPIProto() string
- func (s *Service) RegisterStatus(key string, stat Statuser) error
- func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Service) Start() error
- type Statuser
- type Store
Constants ¶
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 ¶
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 CheckHTTPS ¶
CheckHTTPS returns true if the given URL uses HTTPS.
func EnsureHTTPS ¶
EnsureHTTPS modifies the given URL, ensuring it is using the HTTPS protocol.
func NormalizeAddr ¶
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 // HasAnyPerm returns whether username has any of the given perms. HasAnyPerm(username string, perm ...string) bool }
CredentialStore is the interface credential stores must support.
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.
type Service ¶
type Service struct { CACertFile string // Path to root X.509 certificate. CertFile string // Path to SSL certificate. KeyFile string // Path to SSL private key. TLS1011 bool // Whether older, deprecated TLS should be supported. 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) CheckRequestPerm ¶
CheckRequestPerm returns true if authentication is enabled and the user contained in the BasicAuth request has either PermAll, or the given perm.
func (*Service) FormRedirect ¶
FormRedirect returns the value for the "Location" header for a 301 response.
func (*Service) LeaderAPIAddr ¶
LeaderAPIAddr returns the API address of the leader, as known by this node.
func (*Service) LeaderAPIProto ¶
LeaderAPIProto returns the protocol used by the leader, as known by this node.
func (*Service) RegisterStatus ¶
RegisterStatus allows other modules to register status for serving over HTTP.
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, metadata map[string]string) error // Remove removes the node, specified by id, from the cluster. Remove(id string) error // Metadata returns the value for the given node ID, for the given key. Metadata(id, key string) string // Leader returns the Raft address of the leader of the cluster. LeaderID() (string, error) // Stats returns stats on the Store. Stats() (map[string]interface{}, 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.