Documentation
¶
Index ¶
Constants ¶
const DefaultDataset = "production"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Callbacks ¶
type Callbacks struct {
OnErrorWillRetry func(error)
OnQueryResult func(*QueryResult)
}
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements a client for interacting with the Sanity API.
func New ¶
New returns a new client. A project ID must be provided. Zero or more options can be passed. For example:
client := sanity.New("foobar123",
sanity.WithCDN(true), sanity.WithToken("mytoken"))
func (*Client) Mutate ¶
Mutate performs a post. will receive the result. json.Unmarshal is used to deserialize the JSON; if the type supports json.Unmarshaller, then it can override the unmarshalling.
On API failure, this will return an error of type *RequestError.
func (*Client) Query ¶
func (c *Client) Query(ctx context.Context, query string, out interface{}, params ...Parameter) error
Query performs a query. The out parameter must point to a value or struct that will receive the result. json.Unmarshal is used to deserialize the JSON; if the type supports json.Unmarshaller, then it can override the unmarshalling.
Zero or more parameters can be passed. For simplicity, use the Param() function to construct each parameter.
On API failure, this will return an error of type *RequestError.
type MutateQueryResult ¶
type MutateQueryResult struct {
TransactionID string `json:"transactionId"`
Results *json.RawMessage `json:"results"`
}
MutateQueryResult holds the result of a query API call.
type Option ¶
func WithBackoff ¶
WithBackoff returns an option that configures network request backoff. For how backoff works, see the underlying backoff package: https://github.com/jpillora/backoff. By default, the client uses the backoff package's default (maximum 10 seconds wait, backoff factor of 2).
func WithCallbacks ¶
WithCallbacks returns an option that enables callbacks for common events such as errors.
func WithDataset ¶
WithDataset returns an option that sets the dataset name.
func WithHTTPClient ¶
WithHTTPClient returns an option for setting a custom HTTP client.
type Parameter ¶
type Parameter struct {
// Name is the name of the parameter, which can be used in the query as $name.
Name string
// Value is the value of the parameter. The value must be JSON-serializable.
Value interface{}
}
Parameter is a query parameter.
type QueryResult ¶
type QueryResult struct {
// Ms is the time taken, in milliseconds.
Ms float64 `json:"ms"`
// Query is the GROQ query.
Query string `json:"query"`
// Result is the raw JSON of the query result.
Result *json.RawMessage `json:"result"`
}
QueryResult holds the result of a query API call.
type RequestError ¶
type RequestError struct {
// Request is the attempted HTTP request that failed.
Request *http.Request
// Response is the HTTP response. Note that the body will no longer be valid.
Response *http.Response
// Body is the body of the response.
Body []byte
}
RequestError is returned for API requests that fail with a non-successful HTTP status code.
func (*RequestError) Error ¶
func (e *RequestError) Error() string
Error implements the error interface.