server

package
v0.0.0-...-3f89aaf Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOffsetNotFound = fmt.Errorf("offset not found")

ErrOffsetNotFound is an error returned if there are no records at the given offset.

Functions

func NewGRPCServer

func NewGRPCServer(
	config *Config,
	opts ...grpc.ServerOption,
) (*grpc.Server, error)

NewGRPCServer creates a new gRPC server and registers the log server with it.

func NewHTTPServer

func NewHTTPServer(addr string) *http.Server

NewHTTPServer takes in an address for the server to run on and returns a server handling POST and GET requests to root.

Types

type Authorizer

type Authorizer interface {
	Authorize(subject, object, action string) error
}

Authorizer holds authorization methods.

type CommitLog

type CommitLog interface {
	Append(*api.Record) (uint64, error)
	Read(uint64) (*api.Record, error)
}

type Config

type Config struct {
	CommitLog   CommitLog
	Authorizer  Authorizer
	GetServerer GetServerer
}

Config holds configuration for the server.

type ConsumeRequest

type ConsumeRequest struct {
	Offset uint64 `json:"offset"`
}

ConsumeRequest holds the offset a requester wants to read logs from.

type ConsumeResponse

type ConsumeResponse struct {
	Record Record `json:"record"`
}

ConsumeResponse holds a record read from a Log.

type GetServerer

type GetServerer interface {
	GetServers() ([]*api.Server, error)
}

GetServerer holds methods to expose available servers.

type Log

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

Log holds the records logged.

func NewLog

func NewLog() *Log

NewLog instanciates a Log.

func (*Log) Append

func (c *Log) Append(record Record) (uint64, error)

Append adds a new record to the given Log.

func (*Log) Read

func (c *Log) Read(offset uint64) (Record, error)

Read reads the record at the given offset in the Log.

type ProduceRequest

type ProduceRequest struct {
	Record Record `json:"record"`
}

ProduceRequest contains the record that the requester wants to log.

type ProduceResponse

type ProduceResponse struct {
	Offset uint64 `json:"offset"`
}

ProduceResponse holds the offset an record was logged at.

type Record

type Record struct {
	Value  []byte `json:"value"`
	Offset uint64 `json:"offset"`
}

Record is an value logged at a given offset.

Jump to

Keyboard shortcuts

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