Documentation ¶
Overview ¶
Package karigo provides an HTTP API framework where the business logic is executed through transactions appended to an ordered log. The storage is seen as a list of keys and values and the transactions are simply a list of updates to apply to the keys.
An ordered log is an easy data structure to implement and mutate. In karigo, the log is meant to be exposed and handled directly. Components like search indexes and caches can simply read the log to stay up-to-date. The log can also be easily replicated through a consencus algorithm like Raft to improve avalaibility.
Index ¶
Constants ¶
const ( GET = "GET" POST = "POST" PATCH = "PATCH" DELETE = "DELETE" )
Methods
Variables ¶
var ( // ErrCantDo should be returned by a source that is given a valid query // that it is unable to do. ErrCantDo = errors.New("can't do the given query") // ErrNotFound is returned when an endpoint does not exist. ErrNotFound = errors.New("resource not found") // ErrUnexpected is returned when an unexpected error occurs. ErrUnexpected = errors.New("unexpected error") // ErrNotImplemented is returned when an endpoint exists but is not // implemented. ErrNotImplemented = errors.New("not implemented") )
Functions ¶
Types ¶
type Checkpoint ¶
Checkpoint ...
func (*Checkpoint) Collection ¶
func (c *Checkpoint) Collection(qry query.Col) jsonapi.Collection
Collection ...
type Config ¶
type Config struct { // Server Port uint // Node Hosts []string Journal map[string]string Sources map[string]map[string]string }
Config ...
type Journal ¶
type Journal interface { Service // Reset empties the whole journal. The next append // will add an entry add index 0. Reset() error // Append appends an entry to the journal. Append([]byte) error // Oldest returns the oldest known entry. Oldest() (uint, []byte, error) // Newest returns the newest entry. Newest() (uint, []byte, error) // At returns the entry indexed at i, or none if it // does not exist. At(i uint) ([]byte, error) // Cut removes all entries from the oldest one to // the one at i minus one. // // If i is lower than the oldest known index, // nothing gets cut. If i is greater than the newest // index, it will be interpreted as the newest index, // and therefore everything will be cut except i, // leaving a journal of length one. Cut(i uint) error // Range returns a slice of entries from indexes f // to t (inclusively). // // It returns an error if it can't return the range, // whether it is because the journal's history starts // after f or t is greater than the newest index. Range(f uint, t uint) ([][]byte, error) }
Journal ...
type Node ¶
type Node struct { Name string Hosts []string Journal map[string]string Sources map[string]map[string]string sync.Mutex // contains filtered or unexported fields }
Node ...
type Request ¶
type Request struct { ID string Method string URL *jsonapi.URL Body []byte Doc *jsonapi.Document Logger zerolog.Logger }
Request ...
type Server ¶
Server ...
func (*Server) DisableLogger ¶
func (s *Server) DisableLogger()
type Service ¶
type Service interface { // Connect instantiates a connection to the service behind // the source. // // Implementations should document the elements they expect // in the map. Connect(map[string]string) error // Ping reports whether there is an active connection or not. Ping() bool }
A Service is the interface to handle external services, whether they are on the same host or another one.
This is used for managing journals and sources. If an implementation does not represent an external service, the methods can pretend every is fine. For example, Connect could always return nil.
type Source ¶
type Source interface { Service // Reset wipes all data and brings the underlying database // to a clean state. // // A clean state represents the given schema. Reset(*jsonapi.Schema) error // NewTx returns a new Tx object. NewTx() (query.Tx, error) }
A Source is the interface used by karigo to query data from a database and apply operations to mutate the data.
Each of the interface's methods have comments to explain how to implement a Source. See the current implementations for more details.