Documentation
¶
Index ¶
- Constants
- func ErrorToJsonString(prepend string, err error) string
- func ReadReply[T any](reply *Reply) *T
- type Client
- type CollectionReverseRelations
- type Credentials
- type Environment
- type Reply
- type ReplyStatus
- type Request
- type RequestInterface
- type StreamingRequestInterface
- type Webservice
- func (ws *Webservice) AnswerRequest(w http.ResponseWriter, request RequestInterface, rawData []byte, ...)
- func (ws *Webservice) Close()
- func (ws *Webservice) DbPath(namespace string) string
- func (ws *Webservice) DropCollection(namespace, collection string) error
- func (ws *Webservice) GetAccount(account string) *tiedb.Collection
- func (ws *Webservice) GetCollection(namespace, collection string) *tiedb.Collection
- func (ws *Webservice) ListenAndServe(routes func(*http.ServeMux))
- func (ws *Webservice) RequestHandler(w http.ResponseWriter, r *http.Request)
- type WebserviceConfig
Constants ¶
const (
ReplyTypeEmpty = "Empty"
)
Variables ¶
This section is empty.
Functions ¶
func ErrorToJsonString ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) RunStream ¶
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 ¶
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 Environment ¶
type Environment struct {
Username string
Account func(account string) *tiedb.Collection
Collection func(namespace, collection string) *tiedb.Collection
Webservice *Webservice
}
type ReplyStatus ¶
type Request ¶
type Request struct {
Id string
ReplyStructPtr interface{}
}
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
}