node

package
v0.0.0-...-efb87f3 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNoLeader will be returned if an operation requires a leader - but
	// we have none.
	ErrNoLeader = errors.New("no leader")
)

Functions

This section is empty.

Types

type HTTPStream

type HTTPStream struct {
	// contains filtered or unexported fields
}

HTTPStream implements a raft stream for use with Golang's net/http.

func NewHTTPStream

func NewHTTPStream(addr string, certificates []tls.Certificate, coreCA *ca.CA) (*HTTPStream, error)

NewHTTPStream will instantiate a new HTTPStream.

func (*HTTPStream) Accept

func (h *HTTPStream) Accept() (net.Conn, error)

Accept waits for and returns the next connection to the listener.

func (*HTTPStream) Addr

func (h *HTTPStream) Addr() net.Addr

Addr returns the listener's network address.

func (*HTTPStream) Close

func (h *HTTPStream) Close() error

Close closes the listener. Any blocked Accept operations will be unblocked and return errors.

func (*HTTPStream) Dial

func (h *HTTPStream) Dial(address raft.ServerAddress, timeout time.Duration) (net.Conn, error)

Dial will dial a remote http endpoint (and implement raft.StreamLayer).

func (*HTTPStream) Network

func (h *HTTPStream) Network() string

Network implements net.Addr.

func (*HTTPStream) ServeHTTP

func (h *HTTPStream) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

func (*HTTPStream) String

func (h *HTTPStream) String() string

String implements net.Addr.

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node represents a single gansoi node.

func NewNode

func NewNode(stream raft.StreamLayer, datadir string, db database.Reader, fsm raft.FSM, self string, pair []tls.Certificate, coreCA *ca.CA) (*Node, func() error, error)

NewNode will initialize a new node.

func (*Node) AddPeer

func (n *Node) AddPeer(name string) error

AddPeer adds a new cluster/raft peer.

func (*Node) All

func (n *Node) All(to interface{}, limit int, skip int, reverse bool) error

All lists all kinds of a type.

func (*Node) Bootstrap

func (n *Node) Bootstrap() error

Bootstrap will start a new Gansoi cluster. This should only be called for new clusters. Not new nodes in a existing cluster.

func (*Node) Delete

func (n *Node) Delete(data interface{}) error

Delete deletes one record.

func (*Node) Find

func (n *Node) Find(field string, value interface{}, to interface{}, limit int, skip int, reverse bool) error

Find find objects of type.

func (*Node) LastIndex

func (n *Node) LastIndex() uint64

LastIndex returns the last Raft index in stable storage, either from the last log or from the last snapshot.

func (*Node) LeaderCh

func (n *Node) LeaderCh() <-chan bool

LeaderCh is used to get a channel which delivers signals on acquiring or losing leadership. It sends true if we become the leader, and false if we lose it.

func (*Node) One

func (n *Node) One(fieldName string, value interface{}, to interface{}) error

One will retrieve one record from the cluster database.

func (*Node) PostApply

func (n *Node) PostApply(_ bool, command database.Command, data interface{})

PostApply satisfies the database.Listener interface.

func (*Node) RegisterListener

func (n *Node) RegisterListener(listener database.Listener)

RegisterListener will register a listener for new changes to the database.

func (*Node) Router

func (n *Node) Router(router *gin.RouterGroup)

Router can be used to assign a Gin routergroup.

func (*Node) Run

func (n *Node) Run()

Run will start a few background tasks needed for the node.

func (*Node) Save

func (n *Node) Save(data interface{}) error

Save will save an object to the cluster database.

type RestAPI

type RestAPI[T any] struct {
	// contains filtered or unexported fields
}

RestAPI is a generic way to build a REST-based API for the cluster database.

func NewRestAPI

func NewRestAPI[T any](db database.ReadWriter) *RestAPI[T]

NewRestAPI will instantiate a new RestAPI.

func (*RestAPI[T]) Router

func (r *RestAPI[T]) Router(router *gin.RouterGroup)

Router can be used to assign a Gin routergroup.

Jump to

Keyboard shortcuts

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