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 Dial(target string) (*grpc.ClientConn, error)
- func EncodeSegment(segment string) string
- func MutateStream(ctx context.Context, client pb.StoreServiceClient, options MutateStreamOptions) error
- func ReadStream(ctx context.Context, client pb.StoreServiceClient, options ReadStreamOptions) error
- type AtomicTransformOptions
- type AtomicTransformRequest
- type Client
- func (c *Client) AtomicTransform(ctx context.Context, options AtomicTransformOptions) (*MutationResult, error)
- func (c *Client) Close() error
- func (c *Client) Create(ctx context.Context, options WriteOptions) (*MutationResult, error)
- func (c *Client) Delete(ctx context.Context, options DeleteOptions) (*MutationResult, error)
- func (c *Client) Mutate(ctx context.Context, options MutateOptions) ([]*MutationResult, error)
- func (c *Client) MutateStream(ctx context.Context, options MutateStreamOptions) error
- func (c *Client) Native(ctx context.Context, options NativeOptions) (*NativeResult, error)
- func (c *Client) Put(ctx context.Context, options WriteOptions) (*MutationResult, error)
- func (c *Client) Read(ctx context.Context, options ReadOptions) ([]*ReadResult, error)
- func (c *Client) ReadOne(ctx context.Context, options ReadOneOptions) (*ReadResult, error)
- func (c *Client) ReadStream(ctx context.Context, options ReadStreamOptions) error
- func (c *Client) Replace(ctx context.Context, options WriteOptions) (*MutationResult, error)
- type DeleteOptions
- type DeleteRequest
- type Document
- type Failure
- type FailureCode
- type HTTPNativeResponse
- type LuaTransform
- type MutateOptions
- type MutateRequest
- type MutateStreamOptions
- type MutationAction
- type MutationOptions
- type MutationOutcome
- type MutationResult
- func AtomicTransform(ctx context.Context, client pb.StoreServiceClient, ...) (*MutationResult, error)
- func Create(ctx context.Context, client pb.StoreServiceClient, options WriteOptions) (*MutationResult, error)
- func Delete(ctx context.Context, client pb.StoreServiceClient, options DeleteOptions) (*MutationResult, error)
- func Mutate(ctx context.Context, client pb.StoreServiceClient, options MutateOptions) ([]*MutationResult, error)
- func Put(ctx context.Context, client pb.StoreServiceClient, options WriteOptions) (*MutationResult, error)
- func Replace(ctx context.Context, client pb.StoreServiceClient, options WriteOptions) (*MutationResult, error)
- type MutationVisibility
- type NativeCompletion
- type NativeOptions
- type NativeRequest
- type NativeResponse
- type NativeResult
- type ReadOneOptions
- type ReadOptions
- type ReadRequest
- type ReadResult
- type ReadStreamOptions
- type WriteOptions
- type WriteRequest
Constants ¶
const ( MutationNotStarted = pb.MutationOutcome_NOT_STARTED MutationNotApplied = pb.MutationOutcome_NOT_APPLIED MutationApplied = pb.MutationOutcome_APPLIED MutationUnknown = pb.MutationOutcome_UNKNOWN MutationApplicationAcknowledged = pb.MutationVisibility_APPLICATION_ACKNOWLEDGED MutationQueryVisible = pb.MutationVisibility_QUERY_VISIBLE 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 Dial ¶
func Dial(target string) (*grpc.ClientConn, error)
Dial creates a low-level connection to any gRPC target for the package-level operation functions. The caller owns target validation and the connection's lifetime.
func EncodeSegment ¶
EncodeSegment encodes one decoded resource path segment, including slashes.
func MutateStream ¶
func MutateStream(ctx context.Context, client pb.StoreServiceClient, options MutateStreamOptions) error
MutateStream never replays a request. Every consumed result is an individual acknowledgement; later failures leave other items unacknowledged.
func ReadStream ¶
func ReadStream(ctx context.Context, client pb.StoreServiceClient, options ReadStreamOptions) error
ReadStream sends each produced read immediately and consumes indexed results. Confirmed callbacks remain valid when a later transport or producer fails.
Types ¶
type AtomicTransformOptions ¶
type AtomicTransformOptions struct {
StoreName string
Request *AtomicTransformRequest
}
type AtomicTransformRequest ¶
type AtomicTransformRequest struct {
Resource string
Lua *LuaTransform
BackendExpression *Document
Options *MutationOptions
}
AtomicTransformRequest requires exactly one of Lua and BackendExpression.
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 ¶
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) AtomicTransform ¶
func (c *Client) AtomicTransform(ctx context.Context, options AtomicTransformOptions) (*MutationResult, error)
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) Create ¶
func (c *Client) Create(ctx context.Context, options WriteOptions) (*MutationResult, error)
func (*Client) Delete ¶
func (c *Client) Delete(ctx context.Context, options DeleteOptions) (*MutationResult, error)
func (*Client) Mutate ¶
func (c *Client) Mutate(ctx context.Context, options MutateOptions) ([]*MutationResult, error)
Mutate sends its mutations over a stream of the Client, so it moves between servers as MutateStream does and each resource's mutations apply in input order. A later error preserves confirmed results; nil positions remain unacknowledged and may have applied. The call is not a transaction.
func (*Client) MutateStream ¶
func (c *Client) MutateStream(ctx context.Context, options MutateStreamOptions) error
MutateStream sends each produced mutation once there is room and consumes results as they complete, over a gRPC stream of its own that follows the Client's servers, as ReadStream does. Mutations of one resource run in input order, each after the previous one's result, including after a failure. A mutation a server refused is sent again; nothing else is. Each consumed result is an individual acknowledgement, and every result received before a later error is consumed; other mutations stay unacknowledged and may have applied.
func (*Client) Native ¶
func (c *Client) Native(ctx context.Context, options NativeOptions) (*NativeResult, error)
Native sends the request again only when a server refused it with NativeNotStarted before any response.
func (*Client) Put ¶
func (c *Client) Put(ctx context.Context, options WriteOptions) (*MutationResult, error)
func (*Client) Read ¶
func (c *Client) Read(ctx context.Context, options ReadOptions) ([]*ReadResult, error)
Read sends its reads over a stream of the Client, so it moves between servers as ReadStream does. Results retain input order; a later error preserves confirmed items and leaves unconfirmed positions nil.
func (*Client) ReadOne ¶
func (c *Client) ReadOne(ctx context.Context, options ReadOneOptions) (*ReadResult, error)
ReadOne and the other single-record Client methods share a bounded set of long-lived streams with concurrent calls of this Client. A canceled call stops waiting and cancels only its own record, which may still take effect if it is already executing. A record a server refused before it began is sent again, up to four sends within the caller's deadline.
func (*Client) ReadStream ¶
func (c *Client) ReadStream(ctx context.Context, options ReadStreamOptions) error
ReadStream sends each produced read once there is room and consumes results as they complete, over a gRPC stream of its own that follows the Client's servers: it moves to another server when its server stops resolving, refuses a read or reaches the stream lifetime. A read a server refused is sent again; nothing else is. Every result received before a later error is consumed.
func (*Client) Replace ¶
func (c *Client) Replace(ctx context.Context, options WriteOptions) (*MutationResult, error)
type DeleteOptions ¶
type DeleteOptions struct {
StoreName string
Request *DeleteRequest
}
type DeleteRequest ¶
type DeleteRequest struct {
Resource string
Options *MutationOptions
}
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 belongs to the Native chunk consumer and is never retained by this helper.
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 MutateOptions ¶
type MutateOptions struct {
StoreName string
Requests []*MutateRequest
}
MutateOptions describes independent mutations addressed to one Store. It is not a transaction. Same-resource requests execute in input order; different resources may execute concurrently. Cross-RPC ordering follows the database. Do not mutate requests, options or their document bytes until the call returns.
type MutateRequest ¶
type MutateRequest struct {
Resource string
Action MutationAction
Document *Document
Lua *LuaTransform
BackendExpression *Document
Options *MutationOptions
}
MutateRequest describes one mutation. Create, Put and Replace require Document; Delete accepts no payload; AtomicTransform requires Lua or BackendExpression. Options applies to every action. MutationQueryVisible requires visibility to subsequent normal queries before an APPLIED result without Failure. APPLIED with Failure confirms application only. Nil Options or zero Visibility waits for application acknowledgement without a separate visibility guarantee.
type MutateStreamOptions ¶
type MutateStreamOptions struct {
StoreName string
Next func(context.Context) (*MutateRequest, error)
Consume func(context.Context, uint64, *MutationResult) error
}
MutateStreamOptions incrementally produces mutations to one Store. Next returns io.EOF after the final item. Consume receives confirmed results as their records complete, identified by input index; a later error does not revoke those acknowledgements. Items not consumed remain unacknowledged and must never be automatically replayed. Next and Consume run concurrently; synchronize any shared application state. Both callbacks must honor their context and return promptly. Keep yielded requests, options and document bytes immutable until the corresponding Consume call.
type MutationAction ¶
type MutationAction uint8
MutationAction selects one business operation without a protobuf oneof.
const ( MutationCreate MutationAction = iota + 1 MutationPut MutationReplace MutationDelete MutationAtomicTransform )
type MutationOptions ¶
type MutationOptions = pb.MutationOptions
MutationOptions controls completion uniformly for every mutation action. A nil Options or zero Visibility waits for application acknowledgement.
type MutationOutcome ¶
type MutationOutcome = pb.MutationOutcome
type MutationResult ¶
type MutationResult = pb.MutationResult
func AtomicTransform ¶
func AtomicTransform(ctx context.Context, client pb.StoreServiceClient, options AtomicTransformOptions) (*MutationResult, error)
func Create ¶
func Create(ctx context.Context, client pb.StoreServiceClient, options WriteOptions) (*MutationResult, error)
func Delete ¶
func Delete(ctx context.Context, client pb.StoreServiceClient, options DeleteOptions) (*MutationResult, error)
func Mutate ¶
func Mutate(ctx context.Context, client pb.StoreServiceClient, options MutateOptions) ([]*MutationResult, error)
Mutate validates every input before opening one Execute stream. Same-resource mutations execute in input order, including after item failures. A later stream error preserves confirmed results; nil positions remain unacknowledged and may have applied. The call is not a transaction or replayed.
func Put ¶
func Put(ctx context.Context, client pb.StoreServiceClient, options WriteOptions) (*MutationResult, error)
func Replace ¶
func Replace(ctx context.Context, client pb.StoreServiceClient, options WriteOptions) (*MutationResult, error)
type MutationVisibility ¶
type MutationVisibility = pb.MutationVisibility
type NativeCompletion ¶
type NativeCompletion = pb.NativeCompletion
type NativeOptions ¶
type NativeOptions struct {
StoreName string
Request *NativeRequest
Consume func(context.Context, *NativeResponse, []byte) error
}
Native consumes only nonempty response chunks with their validated metadata. Consume completes before the next chunk and must honor its context. An empty response invokes no callback; its metadata is available in NativeResult. Do not mutate response metadata, which remains attached to the final 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
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.
func Native ¶
func Native(ctx context.Context, client pb.StoreServiceClient, options NativeOptions) (*NativeResult, error)
Native consumes response bytes incrementally. Backend errors remain native response data. A validated result remains evidence alongside later RPC errors.
type ReadOneOptions ¶
type ReadOneOptions struct {
StoreName string
Request *ReadRequest
}
ReadOneOptions describes a single read. Use ReadOptions to share one RPC across multiple independent requests in the same Store.
type ReadOptions ¶
type ReadOptions struct {
StoreName string
Requests []*ReadRequest
}
ReadOptions describes a finite read sequence addressed to one Store. Resources are canonical paths relative to StoreName. Results have the input order. Do not mutate requests or their document bytes until the call returns.
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.
func Read ¶
func Read(ctx context.Context, client pb.StoreServiceClient, options ReadOptions) ([]*ReadResult, error)
Read validates every input before opening one Execute stream. Results retain input order. A later stream error preserves already confirmed items; unconfirmed positions remain nil. Requests are never automatically replayed.
func ReadOne ¶
func ReadOne(ctx context.Context, client pb.StoreServiceClient, options ReadOneOptions) (*ReadResult, error)
ReadOne sends one read without replay.
type ReadStreamOptions ¶
type ReadStreamOptions struct {
StoreName string
Next func(context.Context) (*ReadRequest, error)
Consume func(context.Context, uint64, *ReadResult) error
}
ReadStreamOptions produces reads without retaining every input or result. Next returns io.EOF after its final item. Items are validated before they are sent; an invalid later item does not undo earlier requests. Consume receives each confirmed result as its record completes; the index identifies the input, starting at 1. Next and Consume run concurrently; synchronize any shared application state. Both callbacks must honor their context and return promptly. Keep yielded requests and document bytes immutable until the corresponding Consume call.
type WriteOptions ¶
type WriteOptions struct {
StoreName string
Request *WriteRequest
}
type WriteRequest ¶
type WriteRequest struct {
Resource string
Document *Document
Options *MutationOptions
}
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
|