Documentation
¶
Index ¶
- Constants
- type Callbacks
- type Client
- type MutateResult
- type MutationBuilder
- func (mb *MutationBuilder) Create(doc interface{}) *MutationBuilder
- func (mb *MutationBuilder) CreateIfNotExists(doc interface{}) *MutationBuilder
- func (mb *MutationBuilder) CreateOrReplace(doc interface{}) *MutationBuilder
- func (mb *MutationBuilder) Delete(id string) *MutationBuilder
- func (mb *MutationBuilder) Do(ctx context.Context) (*MutateResult, error)
- func (mb *MutationBuilder) Patch(id string) *PatchBuilder
- func (mb *MutationBuilder) ReturnDocuments(enable bool) *MutationBuilder
- func (mb *MutationBuilder) ReturnIDs(enable bool) *MutationBuilder
- func (mb *MutationBuilder) TransactionID(id string) *MutationBuilder
- func (mb *MutationBuilder) Visibility(v api.MutationVisibility) *MutationBuilder
- type Option
- type PatchBuilder
- func (pb *PatchBuilder) Dec(path string, n float64) *PatchBuilder
- func (pb *PatchBuilder) End() *MutationBuilder
- func (pb *PatchBuilder) IfRevisionID(id string) *PatchBuilder
- func (pb *PatchBuilder) Inc(path string, n float64) *PatchBuilder
- func (pb *PatchBuilder) InsertAfter(path string, items ...interface{}) *PatchBuilder
- func (pb *PatchBuilder) InsertBefore(path string, items ...interface{}) *PatchBuilder
- func (pb *PatchBuilder) InsertReplace(path string, items ...interface{}) *PatchBuilder
- func (pb *PatchBuilder) Query(query string) *PatchBuilder
- func (pb *PatchBuilder) Set(path string, val interface{}) *PatchBuilder
- func (pb *PatchBuilder) SetIfMissing(path string, val interface{}) *PatchBuilder
- func (pb *PatchBuilder) Unset(paths ...string) *PatchBuilder
- type QueryBuilder
- type QueryResult
- type RequestError
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 ¶
func (c *Client) Mutate() *MutationBuilder
Mutate returns a new mutation builder.
func (*Client) Query ¶
func (c *Client) Query(query string) *QueryBuilder
Query returns a new query builder.
type MutateResult ¶
type MutateResult struct { TransactionID string Results []*api.MutateResultItem }
type MutationBuilder ¶
type MutationBuilder struct {
// contains filtered or unexported fields
}
func (*MutationBuilder) Create ¶
func (mb *MutationBuilder) Create(doc interface{}) *MutationBuilder
func (*MutationBuilder) CreateIfNotExists ¶
func (mb *MutationBuilder) CreateIfNotExists(doc interface{}) *MutationBuilder
func (*MutationBuilder) CreateOrReplace ¶
func (mb *MutationBuilder) CreateOrReplace(doc interface{}) *MutationBuilder
func (*MutationBuilder) Delete ¶
func (mb *MutationBuilder) Delete(id string) *MutationBuilder
func (*MutationBuilder) Do ¶
func (mb *MutationBuilder) Do(ctx context.Context) (*MutateResult, error)
func (*MutationBuilder) Patch ¶
func (mb *MutationBuilder) Patch(id string) *PatchBuilder
func (*MutationBuilder) ReturnDocuments ¶
func (mb *MutationBuilder) ReturnDocuments(enable bool) *MutationBuilder
func (*MutationBuilder) ReturnIDs ¶
func (mb *MutationBuilder) ReturnIDs(enable bool) *MutationBuilder
func (*MutationBuilder) TransactionID ¶
func (mb *MutationBuilder) TransactionID(id string) *MutationBuilder
func (*MutationBuilder) Visibility ¶
func (mb *MutationBuilder) Visibility(v api.MutationVisibility) *MutationBuilder
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 WithBaseURL ¶
WithBaseURL returns an option that changes the API URL.
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 PatchBuilder ¶
type PatchBuilder struct {
// contains filtered or unexported fields
}
func (*PatchBuilder) Dec ¶
func (pb *PatchBuilder) Dec(path string, n float64) *PatchBuilder
func (*PatchBuilder) End ¶
func (pb *PatchBuilder) End() *MutationBuilder
func (*PatchBuilder) IfRevisionID ¶
func (pb *PatchBuilder) IfRevisionID(id string) *PatchBuilder
func (*PatchBuilder) Inc ¶
func (pb *PatchBuilder) Inc(path string, n float64) *PatchBuilder
func (*PatchBuilder) InsertAfter ¶
func (pb *PatchBuilder) InsertAfter(path string, items ...interface{}) *PatchBuilder
func (*PatchBuilder) InsertBefore ¶
func (pb *PatchBuilder) InsertBefore(path string, items ...interface{}) *PatchBuilder
func (*PatchBuilder) InsertReplace ¶
func (pb *PatchBuilder) InsertReplace(path string, items ...interface{}) *PatchBuilder
func (*PatchBuilder) Query ¶
func (pb *PatchBuilder) Query(query string) *PatchBuilder
func (*PatchBuilder) Set ¶
func (pb *PatchBuilder) Set(path string, val interface{}) *PatchBuilder
func (*PatchBuilder) SetIfMissing ¶
func (pb *PatchBuilder) SetIfMissing(path string, val interface{}) *PatchBuilder
func (*PatchBuilder) Unset ¶
func (pb *PatchBuilder) Unset(paths ...string) *PatchBuilder
type QueryBuilder ¶
type QueryBuilder struct {
// contains filtered or unexported fields
}
QueryBuilder is a builder for queries.
func (*QueryBuilder) Do ¶
func (qb *QueryBuilder) Do(ctx context.Context) (*QueryResult, error)
Query performs the query. On API failure, this will return an error of type *RequestError.
func (*QueryBuilder) Param ¶
func (qb *QueryBuilder) Param(name string, val interface{}) *QueryBuilder
Param adds a query parameter. For example, Param("foo", "bar") makes $foo usable inside the query. The passed-in value must be serializable to a JSON primitive.
type QueryResult ¶
type QueryResult struct { // Time is the time taken. Time time.Duration // Result is the raw JSON of the query result. Result *json.RawMessage }
QueryResult holds the result of a query API call.
func (*QueryResult) Unmarshal ¶
func (q *QueryResult) Unmarshal(dest interface{}) error
Unmarshal unmarshals the result into a Go value or struct. If there were no results, the destination value is set to the zero value.
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.