Documentation
¶
Index ¶
- type AuthMode
- type Client
- type ClientBuilder
- func (cb *ClientBuilder) Build() (*Client, error)
- func (cb *ClientBuilder) WithHTTPAuth(user, password string) *ClientBuilder
- func (cb *ClientBuilder) WithInlineAuth(user, password string) *ClientBuilder
- func (cb *ClientBuilder) WithURL(url string) *ClientBuilder
- func (cb *ClientBuilder) WithURLComponents(protocol Protocol, host string, port int, databaseId string) *ClientBuilder
- func (cb *ClientBuilder) WithURLComponentsNoPort(protocol Protocol, host string, databaseId string) *ClientBuilder
- type Protocol
- type Request
- type RequestBuilder
- func (rb *RequestBuilder) AddQuery(query string) *RequestBuilder
- func (rb *RequestBuilder) AddStatement(statement string) *RequestBuilder
- func (rb *RequestBuilder) Build() (*Request, error)
- func (rb *RequestBuilder) WithDecoder(password string, fields ...string) *RequestBuilder
- func (rb *RequestBuilder) WithEncoder(password string, fields ...string) *RequestBuilder
- func (rb *RequestBuilder) WithEncoderAndCompression(password string, compressionLevel int, fields ...string) *RequestBuilder
- func (rb *RequestBuilder) WithNoFail() *RequestBuilder
- func (rb *RequestBuilder) WithValues(values map[string]interface{}) *RequestBuilder
- type Response
- type ResponseItem
- type WsError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
ClientBuilder
}
This struct represent a client for ws4sqlite. It can be constructed using the ClientBuilder struct, that configures it with the URL to contact and the authorization (if any). Once instantiated, it can be used to send Requests to the server.
Example:
cli, err := ws4.NewClientBuilder().
WithURL("http://localhost:12321/db2").
WithInlineAuth("myUser1", "myHotPassword").
Build()
cli.Send(...)
func (*Client) Send ¶
Sends a set of requests to the remote, wrapped in a Request struct. Returns a matching set of responses, wrapped in a Response struct.
Returns a WsError if the remote service returns a processing error. If the communication fails, it returns the "naked" error, so check for cast-ability.
func (*Client) SendWithContext ¶ added in v0.11.1
SendWithContext sends a set of requests to the remote with context, wrapped in a Request. Returns a matching set of responses, wrapped in a Response struct.
Returns a WsError if the remote service returns a processing error. If the communication fails, it returns the "naked" error, so check for cast-ability.
type ClientBuilder ¶
type ClientBuilder struct {
// contains filtered or unexported fields
}
This class is a builder for Client instances. Once configured with the URL to contact and the authorization (if any), it can be used to instantiate a Client.
Example:
cli, err := ws4.NewClientBuilder().
WithURL("http://localhost:12321/db2").
WithInlineAuth("myUser1", "myHotPassword").
Build()
cli.Send(...)
func NewClientBuilder ¶
func NewClientBuilder() *ClientBuilder
First step when building. Generates a new ClientBuilder instance.
func (*ClientBuilder) Build ¶
func (cb *ClientBuilder) Build() (*Client, error)
Returns the Client that was built.
func (*ClientBuilder) WithHTTPAuth ¶
func (cb *ClientBuilder) WithHTTPAuth(user, password string) *ClientBuilder
Builder methods that configures HTTP Basic Authentication; the remote must be configured accordingly.
func (*ClientBuilder) WithInlineAuth ¶
func (cb *ClientBuilder) WithInlineAuth(user, password string) *ClientBuilder
Builder methods that configures INLINE authentication; the remote must be configured accordingly.
func (*ClientBuilder) WithURL ¶
func (cb *ClientBuilder) WithURL(url string) *ClientBuilder
Builder methods that adds a "raw" URL for contacting the ws4sqlite remote.
func (*ClientBuilder) WithURLComponents ¶
func (cb *ClientBuilder) WithURLComponents(protocol Protocol, host string, port int, databaseId string) *ClientBuilder
Builder methods that adds an URL for contacting the ws4sqlite remote, given its components.
func (*ClientBuilder) WithURLComponentsNoPort ¶
func (cb *ClientBuilder) WithURLComponentsNoPort(protocol Protocol, host string, databaseId string) *ClientBuilder
Builder methods that adds an URL for contacting the ws4sqlite remote, given its components but with an implicit port.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Container class for a request to ws4sqlite. Built with RequestBuilder.
type RequestBuilder ¶
type RequestBuilder struct {
// contains filtered or unexported fields
}
A builder class to build a Request to send to the ws4sqlite server with the <Client>.Send(Request) method.
If an error is encountered during built, it's returned at Build() time, to be able to chain.
func NewRequestBuilder ¶
func NewRequestBuilder() *RequestBuilder
First step when building. Generates a new RequestBuilder instance.
func (*RequestBuilder) AddQuery ¶
func (rb *RequestBuilder) AddQuery(query string) *RequestBuilder
Adds a new request to the list, for a query. It must be configured later on with the proper methods.
func (*RequestBuilder) AddStatement ¶
func (rb *RequestBuilder) AddStatement(statement string) *RequestBuilder
Adds a new request to the list, for a statement. It must be configured later on with the proper methods.
func (*RequestBuilder) Build ¶
func (rb *RequestBuilder) Build() (*Request, error)
Returns the Request that was built, returning also any error that was encountered during build.
func (*RequestBuilder) WithDecoder ¶
func (rb *RequestBuilder) WithDecoder(password string, fields ...string) *RequestBuilder
Add a decoder to the request. Allowed only for queries.
func (*RequestBuilder) WithEncoder ¶
func (rb *RequestBuilder) WithEncoder(password string, fields ...string) *RequestBuilder
Add an encoder to the request. Allowed only for statements.
func (*RequestBuilder) WithEncoderAndCompression ¶
func (rb *RequestBuilder) WithEncoderAndCompression(password string, compressionLevel int, fields ...string) *RequestBuilder
Add an encoder to the request, with compression. Allowed only for statements.
func (*RequestBuilder) WithNoFail ¶
func (rb *RequestBuilder) WithNoFail() *RequestBuilder
Specify that the request must not cause a general failure.
func (*RequestBuilder) WithValues ¶
func (rb *RequestBuilder) WithValues(values map[string]interface{}) *RequestBuilder
Adds a list of values (ok, amap) for the request. If there's already one, it creates a batch.
type Response ¶
type Response struct {
// Slice with the results, each one is a ResponseItem
Results []ResponseItem
}
Response coming from the endpoint, that is a list of single responses matching the list of request that were submitted. The single responses are of type ResponseItem.
type ResponseItem ¶
type ResponseItem struct {
// Was the request successful?
Success bool
// If the node was a statement and no batching was involved, it's the number of updated
// rows
RowsUpdated *int64
// If the node was a statement and a batch of values was provided, it's a slice of the
// numbers of updated rows for each batch item
RowsUpdatedBatch []int64
// If the node was a query, it's a slice of maps with an item per returned record, and
// each map has the name of the filed as a key of each entry, and the value as a value
ResultSet []map[string]interface{}
// Reason for the error, if the request wasn't successful
Error string
}
Single response coming from ws4sqlite. Every ResponseItem matches a node of the request, and each one has exactly one of the following fields populated/not null:
- Error: reason for the error, if it wasn't successful;
- RowsUpdated: if the node was a statement and no batching was involved; it's the number of updated rows;
- RowsUpdatedBatch: if the node was a statement and a batch of values was provided; it's a slice of the numbers of updated row for each batch item;
- ResultSet: if the node was a query; it's a slice of maps with an item per returned record, and each map has the name of the filed as a key of each entry, and the value as a value.
type WsError ¶
type WsError struct {
// The index of the statement/query that failed
RequestIdx int `json:"reqIdx"`
// Error message
Msg string `json:"error"`
// HTTP code
Code int `json:"-"`
}
This is an exception that wraps the error structure of ws4sqlite. See the docs at https://germ.gitbook.io/ws4sqlite/documentation/errors#global-errors
It has fields for the error message, the index of the node that failed, and for the HTTP code.</p>