webservice

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReplyTypeEmpty = "Empty"
)

Variables

This section is empty.

Functions

func ErrorToJsonString

func ErrorToJsonString(prepend string, err error) string

func ReadReply

func ReadReply[T any](reply *Reply) *T

Types

type Client

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

func NewClient

func NewClient(server, username, password string, insecure bool) *Client

func (*Client) Run

func (c *Client) Run(request RequestInterface) (*Reply, error)

func (*Client) RunStream

func (c *Client) RunStream(request RequestInterface, consume func(io.Reader) error) error

RunStream POSTs the request and hands the raw, unparsed response body to consume, which reads it incrementally (e.g. NDJSON). The body is never fully buffered in memory. Auth and non-200 failures are reported before consume is called; a failure mid-stream surfaces as a read error inside consume.

type CollectionReverseRelations

type CollectionReverseRelations struct {
	Namespace  string
	Collection string
	Relations  []string
}

CollectionReverseRelations overrides the reverse-relation set for one collection. Relations lists the value1 relations that collection indexes in reverse (replacing the WebserviceConfig.ReverseRelations default for it).

type Credentials

type Credentials struct {
	Username string
	Password string
}

type Environment

type Environment struct {
	Username   string
	Account    func(account string) *tiedb.Collection
	Collection func(namespace, collection string) *tiedb.Collection
	Webservice *Webservice
}

type Reply

type Reply struct {
	RequestName    string
	ReplyStructPtr interface{}
}

type ReplyStatus

type ReplyStatus struct {
	Success bool
	Message string
	OrigKey string
}

type Request

type Request struct {
	Id             string
	ReplyStructPtr interface{}
}

func (*Request) GetId

func (r *Request) GetId() string

func (*Request) GetReplyStructPtr

func (r *Request) GetReplyStructPtr() interface{}

type RequestInterface

type RequestInterface interface {
	GetId() string
	GetReplyStructPtr() interface{}
	Reply(environment *Environment) (Reply, error)
	// New returns a fresh, zero-valued instance of the same concrete request
	// type. RequestHandler unmarshals each incoming request into its own New()
	// instance so concurrent requests never share mutable state.
	New() RequestInterface
}

type StreamingRequestInterface

type StreamingRequestInterface interface {
	RequestInterface
	StreamReply(environment *Environment, w io.Writer) error
}

StreamingRequestInterface is an optional interface a request may implement to write its reply directly to the response writer (e.g. NDJSON, one record per line) instead of returning a fully-buffered Reply. AnswerRequest prefers this path when present, so neither the server nor the client materializes the whole reply in memory. Once the first byte is written the HTTP status is committed, so a mid-stream error cannot change it (it can only be logged).

type Webservice

type Webservice struct {
	Config WebserviceConfig
	// contains filtered or unexported fields
}

func NewWebservice

func NewWebservice(config WebserviceConfig, requests []RequestInterface) *Webservice

func (*Webservice) AnswerRequest

func (ws *Webservice) AnswerRequest(w http.ResponseWriter, request RequestInterface, rawData []byte, username string)

func (*Webservice) Close

func (ws *Webservice) Close()

Close flushes and closes every collection's disk writer. Call it on shutdown (e.g. from a SIGTERM handler) so the server durably persists its tail of writes rather than relying on the kernel to flush the page cache after exit.

func (*Webservice) DbPath

func (ws *Webservice) DbPath(namespace string) string

func (*Webservice) DropCollection

func (ws *Webservice) DropCollection(namespace, collection string) error

func (*Webservice) GetAccount

func (ws *Webservice) GetAccount(account string) *tiedb.Collection

func (*Webservice) GetCollection

func (ws *Webservice) GetCollection(namespace, collection string) *tiedb.Collection

func (*Webservice) ListenAndServe

func (ws *Webservice) ListenAndServe(routes func(*http.ServeMux))

func (*Webservice) RequestHandler

func (ws *Webservice) RequestHandler(w http.ResponseWriter, r *http.Request)

type WebserviceConfig

type WebserviceConfig struct {
	ListenOn      string
	Insecure      bool
	CertFile      string
	KeyFile       string
	UserNamespace string
	DbPath        string

	// Auth resolves each request's role from its Basic Auth credentials and gates
	// read vs write operations. Access management is done by populating it from
	// the server's config file; it is read-only at runtime.
	Auth *auth.Store

	// ReverseRelations restricts which relations (value1) collections index in
	// reverse. Empty/nil indexes every relation (the original behavior). Set it
	// to just the relations queried in reverse to cut association memory roughly
	// in half on metadata-heavy stores. Acts as the default for collections with
	// no CollectionReverseRelations override.
	ReverseRelations []string

	// CollectionReverseRelations pins the reverse-relation set for specific
	// (namespace, collection) pairs, overriding ReverseRelations. A pair listed
	// here indexes exactly its relations in reverse; unlisted collections use the
	// default. Applied at collection load time, so changes require a restart.
	CollectionReverseRelations []CollectionReverseRelations

	// MaxConcurrentRequests caps how many requests execute simultaneously.
	// Zero or negative means unbounded. tiedb is concurrency-safe, so this is a
	// load-shedding knob, not a correctness requirement.
	MaxConcurrentRequests int
}

Jump to

Keyboard shortcuts

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