Documentation
¶
Overview ¶
Package weir sends typed business requests to the Stores hosted behind one Weir application address. A Client sends a record again only when a server refused it before it began; nothing that may have taken effect is resent.
Index ¶
- Constants
- Variables
- func EncodeSegment(segment string) string
- type Client
- func (c *Client) Close() error
- func (c *Client) Mutate(ctx context.Context, store string, options ...MutateOption) ([]*MutationResult, error)
- func (c *Client) Native(ctx context.Context, store string, request *NativeRequest, ...) (*NativeResult, error)
- func (c *Client) Read(ctx context.Context, store string, options ...ReadOption) ([]*ReadResult, error)
- type ClientOption
- type Document
- type Failure
- type FailureCode
- type HTTPNativeResponse
- type LuaTransform
- type MutateOption
- type MutateRequest
- type MutationAction
- type MutationOutcome
- type MutationResult
- type NativeCompletion
- type NativeOption
- type NativeRequest
- type NativeResponse
- type NativeResult
- type Option
- type ReadOption
- type ReadRequest
- type ReadResult
Constants ¶
const ( MutationNotStarted = pb.MutationOutcome_NOT_STARTED MutationNotApplied = pb.MutationOutcome_NOT_APPLIED MutationApplied = pb.MutationOutcome_APPLIED MutationUnknown = pb.MutationOutcome_UNKNOWN NativeCompletionUnconfirmed = pb.NativeCompletion_NATIVE_COMPLETION_UNSPECIFIED NativeNotStarted = pb.NativeCompletion_NATIVE_NOT_STARTED NativeResponseComplete = pb.NativeCompletion_RESPONSE_COMPLETE NativeResponseIncomplete = pb.NativeCompletion_RESPONSE_INCOMPLETE FailureInvalidArgument = pb.FailureCode_INVALID_ARGUMENT FailureUnauthenticated = pb.FailureCode_UNAUTHENTICATED FailurePermissionDenied = pb.FailureCode_PERMISSION_DENIED FailureTargetNotFound = pb.FailureCode_TARGET_NOT_FOUND FailurePreconditionFailed = pb.FailureCode_PRECONDITION_FAILED FailureConflict = pb.FailureCode_CONFLICT FailureUnsupported = pb.FailureCode_UNSUPPORTED FailureResourceExhausted = pb.FailureCode_RESOURCE_EXHAUSTED FailureCancelled = pb.FailureCode_CANCELLED FailureDeadlineExceeded = pb.FailureCode_DEADLINE_EXCEEDED FailureInternal = pb.FailureCode_INTERNAL )
Variables ¶
var ErrClosed = errors.New("Weir client is closed")
ErrClosed reports a call started after Close. Calls already running when Close is called end with the gRPC cancellation error instead.
Functions ¶
func EncodeSegment ¶
EncodeSegment encodes one decoded resource path segment, including slashes.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client sends business requests to the Weir servers behind one application address. Every server behind the address must host the Stores the client uses. Reuse a Client across goroutines and close it after callers finish. It sends a record again only when a server refused it before it began, and never one that may have taken effect.
func New ¶
func New(address string, options ...ClientOption) (*Client, error)
New returns a Client for a Weir application address such as "weir:7447". The address is a host name or IP literal with an explicit port. The Client connects on first use and reconnects after failures. A DNS name that resolves to several servers, such as a headless Service, spreads streams across them. The Client looks the name up every five seconds: a server that joins takes its share of streams, and one that stops resolving gets no new records while its streams finish the ones they carry.
func (*Client) Close ¶
Close cancels active requests and closes the connection. Concurrent and repeated calls wait for the first and return its result.
func (*Client) Mutate ¶
func (c *Client) Mutate(ctx context.Context, store string, options ...MutateOption) ([]*MutationResult, error)
Mutate sends the mutations of WithRequests and then of WithNext, and returns one result per mutation in input order. Mutations of one resource run in input order, each after the previous one's result, including after a failure; those of different resources may run concurrently. It is not a transaction. A later error preserves confirmed results, and unconfirmed positions stay nil and may have applied. With WithMutateConsume results go to its callback and Mutate returns nil results. It needs at least one mutation, or returns an error.
A single mutation without WithNext, WithMutateConsume or outgoing gRPC metadata shares long-lived streams with concurrent calls. Any other Mutate uses a gRPC stream of its own that follows the Client's servers. A mutation a server refused is sent again; nothing else is.
func (*Client) Native ¶
func (c *Client) Native(ctx context.Context, store string, request *NativeRequest, options ...NativeOption) (*NativeResult, error)
Native sends one backend command and returns its response. Backend errors remain native response data, and a validated result remains evidence alongside a later RPC error. The body is collected into NativeResult.Body unless WithChunks consumes it incrementally. The request is sent again only when a server refused it with NativeNotStarted before any response.
func (*Client) Read ¶
func (c *Client) Read(ctx context.Context, store string, options ...ReadOption) ([]*ReadResult, error)
Read sends the reads of WithRequests and then of WithNext, and returns one result per read in input order. A later error preserves confirmed results, and unconfirmed positions stay nil. With WithReadConsume results go to its callback and Read returns nil results. It needs at least one read, or returns an error.
A single read without WithNext, WithReadConsume or outgoing gRPC metadata shares long-lived streams with concurrent calls. Any other Read uses a gRPC stream of its own that follows the Client's servers. A read a server refused is sent again; nothing else is.
type ClientOption ¶ added in v0.24.0
type ClientOption func(*clientOptions)
ClientOption configures a Client.
func WithDialOptions ¶ added in v0.24.0
func WithDialOptions(options ...grpc.DialOption) ClientOption
WithDialOptions adds gRPC options to a Client's connection, such as a stats handler, an interceptor or a custom dialer. They can replace its defaults for transport credentials and keepalive. They cannot change what a Client relies on: gRPC never resends a record, message sizes stay at the protocol's limit, service configs have no effect, and its own resolver and balancer follow its servers. Stats handlers and interceptors see gRPC streams rather than calls, so they suit stream metrics, not per-call tracing. Several WithDialOptions add their options in order, and a nil one is ignored.
type Document ¶
Leaf DTOs preserve document bytes and backend evidence without exposing any transport framing or protobuf operation selection.
type FailureCode ¶
type FailureCode = pb.FailureCode
FailureCode identifies a declared operation failure. Only known nonzero codes are accepted. A Client sends a record again only for FailureUnavailable on a record that never began.
type HTTPNativeResponse ¶
HTTPNativeResponse describes an application/http metadata document. Its body stays in NativeResult.Body or goes to the WithChunks callback, and this helper never retains it.
func ParseHTTPNativeResponse ¶
func ParseHTTPNativeResponse(response *NativeResponse) (*HTTPNativeResponse, error)
ParseHTTPNativeResponse parses a complete HTTP status line and header block from Native response metadata. No body bytes may follow the terminating CRLF. Other native formats stay opaque and do not require this optional helper.
type LuaTransform ¶
type LuaTransform = pb.LuaTransform
type MutateOption ¶ added in v0.24.0
type MutateOption = Option[*MutateRequest]
MutateOption configures a Mutate.
func WithMutateConsume ¶ added in v0.24.0
func WithMutateConsume(consume func(ctx context.Context, index int, result *MutationResult) error) MutateOption
WithMutateConsume receives each mutation's result as its record completes, instead of the call collecting them, and Mutate returns nil results. The index is the record's position in the input, from 0. Each result is an individual acknowledgement that a later error does not revoke; records without a result may have applied. Calls run one at a time and hold back the input when slow; an error from consume ends the call. It must honor its context, as a call does not return before it does.
func WithQueryVisible ¶ added in v0.24.0
func WithQueryVisible() MutateOption
WithQueryVisible requires every mutation of the call to be visible to later normal queries before an APPLIED result without Failure. APPLIED with Failure confirms application only. Without it, a mutation completes on application acknowledgement, with no separate visibility guarantee.
type MutateRequest ¶
type MutateRequest struct {
Resource string
Action MutationAction
Document *Document
Lua *LuaTransform
BackendExpression *Document
}
MutateRequest describes one mutation. Create, Put and Replace require Document; Delete accepts no payload; AtomicTransform requires Lua or BackendExpression.
type MutationAction ¶
type MutationAction uint8
MutationAction selects one business operation without a protobuf oneof.
const ( MutationCreate MutationAction = iota + 1 MutationPut MutationReplace MutationDelete MutationAtomicTransform )
type MutationOutcome ¶
type MutationOutcome = pb.MutationOutcome
type MutationResult ¶
type MutationResult = pb.MutationResult
type NativeCompletion ¶
type NativeCompletion = pb.NativeCompletion
type NativeOption ¶ added in v0.24.0
type NativeOption func(*nativeOptions)
NativeOption configures a Native call.
func WithChunks ¶ added in v0.24.0
func WithChunks(consume func(ctx context.Context, response *NativeResponse, chunk []byte) error) NativeOption
WithChunks receives a Native response's body incrementally, instead of the call collecting it into NativeResult.Body. Each nonempty chunk finishes before the next one, and consume must honor its context. An empty response invokes no callback. Do not mutate the response metadata, which stays attached to the result.
type NativeRequest ¶
type NativeRequest = pb.NativeRequest
NativeRequest carries an opaque adapter-owned document. Keep its bytes immutable until Native returns. Empty request data is permitted. Resource is an optional target prefix; empty selects the backend root when supported.
func NewHTTPNativeRequest ¶
func NewHTTPNativeRequest(resource string, request *http.Request) (*NativeRequest, error)
NewHTTPNativeRequest serializes a standard HTTP/1.1 request using an origin-form request target. It consumes and closes request.Body. Native imposes no method, path or parameter allowlist. Resource is an optional target prefix; empty addresses the backend root. Host does not select a Store.
type NativeResponse ¶
type NativeResponse = pb.NativeHead
type NativeResult ¶
type NativeResult struct {
Response *NativeResponse
Body []byte
Completion NativeCompletion
Failure *Failure
}
NativeResult retains validated response and completion evidence. Completion is NativeCompletionUnconfirmed until a terminal acknowledgement arrives; Response may already be available. An RPC error never revokes a confirmed terminal. Completion describes response transport, not whether backend writes applied. Body holds the response body of a call without WithChunks, as far as it arrived.
type Option ¶ added in v0.24.0
type Option[Q any] func(*callOptions[Q])
Option configures one Read or Mutate call whose requests have type Q.
func WithNext ¶ added in v0.24.0
WithNext produces requests one at a time, after those of WithRequests have entered the window of 32 records and 8 MiB, without waiting for their results. Next returns io.EOF after the last request. Each request is validated as it is produced. An invalid request or another error from Next ends the input there: the records before it still finish, and the call then returns that error. Next runs concurrently with a consume callback, so synchronize what they share. It must honor its context, and return promptly once that ends. Keep a produced request and its document bytes unchanged until the call returns, or with a consume callback until its result arrives there.
Without a consume callback, results accumulate until the call returns, and memory grows with the number of records.
func WithRequests ¶ added in v0.24.0
WithRequests adds requests the call already holds. They are all validated before anything is sent, so an invalid one rejects the whole call and WithNext is never called. Several WithRequests add their requests in order. Keep the requests and their document bytes unchanged until the call returns, and after a call its context ended do not reuse them at all: a single record's shared stream may still be reading them.
type ReadOption ¶ added in v0.24.0
type ReadOption = Option[*ReadRequest]
ReadOption configures a Read.
func WithReadConsume ¶ added in v0.24.0
func WithReadConsume(consume func(ctx context.Context, index int, result *ReadResult) error) ReadOption
WithReadConsume receives each read's result as its record completes, instead of the call collecting them, and Read returns nil results. The index is the record's position in the input, from 0. Results delivered before a later error remain valid. Calls run one at a time and hold back the input when slow; an error from consume ends the call. It must honor its context, as a call does not return before it does.
type ReadRequest ¶
type ReadRequest = pb.ReadRequest
type ReadResult ¶
ReadResult contains exactly one of Document, Missing, or Failure. Missing confirms document absence after a successful read. FailureTargetNotFound reports a missing adapter-owned target, never a missing document.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
Basic demonstrates typed finite read and mutation batches addressed to one Store.
|
Basic demonstrates typed finite read and mutation batches addressed to one Store. |
|
native
command
Native sends one backend request and consumes its response incrementally.
|
Native sends one backend request and consumes its response incrementally. |
|
read
command
|