Documentation ¶
Index ¶
- Constants
- Variables
- func DeleteRequest(ctx context.Context, url *url.URL, method RestLiMethod) (*http.Request, error)
- func GenerateBatchKeysParam(keyWriter restlicodec.ArrayWriter) (string, error)
- func GetRequest(ctx context.Context, url *url.URL, method RestLiMethod) (*http.Request, error)
- func IsErrorResponse(req *http.Request, res *http.Response) error
- func JsonRequest(ctx context.Context, url *url.URL, httpMethod string, ...) (*http.Request, error)
- func RawJsonRequest(ctx context.Context, url *url.URL, httpMethod string, ...) (*http.Request, error)
- func SetJsonAcceptHeader(req *http.Request)
- func SetJsonContentTypeHeader(req *http.Request)
- func SetRestLiHeaders(req *http.Request, method RestLiMethod)
- type BatchMethodError
- type CreateResponseHasNoEntityHeaderError
- type HostnameResolver
- type LoggingRoundTripper
- type PagingContext
- type RawRecord
- func (r *RawRecord) ComputeHash() (h fnv1a.Hash)
- func (r *RawRecord) Equals(other *RawRecord) bool
- func (r *RawRecord) EqualsInterface(otherInterface interface{}) bool
- func (r *RawRecord) MarshalRestLi(writer restlicodec.Writer) error
- func (r *RawRecord) UnmarshalRestLi(reader restlicodec.Reader) error
- func (r *RawRecord) UnmarshalTo(obj restlicodec.Unmarshaler) error
- type RestLiClient
- func (c *RestLiClient) Do(req *http.Request) (*http.Response, error)
- func (c *RestLiClient) DoActionRequest(ctx context.Context, url *url.URL, params restlicodec.Marshaler, ...) error
- func (c *RestLiClient) DoAndDecode(req *http.Request, v restlicodec.Unmarshaler) (*http.Response, error)
- func (c *RestLiClient) DoAndIgnore(req *http.Request) (*http.Response, error)
- func (c *RestLiClient) DoBatchGetRequest(ctx context.Context, url *url.URL, resultsReader restlicodec.MapReader) (err error)
- func (c *RestLiClient) DoCreateRequest(ctx context.Context, url *url.URL, create restlicodec.Marshaler, ...) (err error)
- func (c *RestLiClient) DoDeleteRequest(ctx context.Context, url *url.URL) error
- func (c *RestLiClient) DoFinderRequest(ctx context.Context, url *url.URL, elements restlicodec.ArrayReader) (total *int, err error)
- func (c *RestLiClient) DoGetRequest(ctx context.Context, url *url.URL, result restlicodec.Unmarshaler) (err error)
- func (c *RestLiClient) DoPartialUpdateRequest(ctx context.Context, url *url.URL, patch restlicodec.Marshaler, ...) error
- func (c *RestLiClient) DoUpdateRequest(ctx context.Context, url *url.URL, update restlicodec.Marshaler) error
- func (c *RestLiClient) FormatQueryUrl(resourceBasename, rawQuery string) (*url.URL, error)
- type RestLiError
- type RestLiMethod
- type RestLiObject
- type SimpleHostnameResolver
- type UnexpectedStatusCodeError
Constants ¶
const ( RestLiProtocolVersion = "2.0.0" RestLiHeader_ID = "X-RestLi-Id" RestLiHeader_Method = "X-RestLi-Method" RestLiHeader_ProtocolVersion = "X-RestLi-Protocol-Version" RestLiHeader_ErrorResponse = "X-RestLi-Error-Response" )
const ( Method_Unknown = RestLiMethod(iota) Method_get Method_create Method_delete Method_update Method_partial_update Method_batch_get Method_batch_create Method_batch_delete Method_batch_update Method_batch_partial_update Method_get_all Method_action Method_finder )
Variables ¶
var EmptyRecord emptyRecord
var RestLiMethodNameMapping = func() map[string]RestLiMethod { mapping := make(map[string]RestLiMethod) for m := Method_get; m <= Method_finder; m++ { mapping[m.String()] = m } return mapping }()
var StandardLogger stdLogger
StandardLogger represents the standard Logger from the log package (log.std for those inclined to read the source code)
Functions ¶
func DeleteRequest ¶ added in v0.17.0
DeleteRequest creates a DELETE http.Request and sets the expected rest.li headers
func GenerateBatchKeysParam ¶ added in v0.19.0
func GenerateBatchKeysParam(keyWriter restlicodec.ArrayWriter) (string, error)
GenerateBatchKeysParam is intended for use by generated code when batch methods have no extra query parameters. Batch methods with query parameters will have a standalone object that includes the "ids" parameter
func GetRequest ¶ added in v0.17.0
GetRequest creates a GET http.Request and sets the expected rest.li headers
func IsErrorResponse ¶
IsErrorResponse checks the contents of the given http.Response and if the X-RestLi-Error-Response is set to `true`, parses the body of the response into a RestLiError. If the header is not set, but the status code isn't a 2xx code, an UnexpectedStatusCodeError will be returned instead. Note that an UnexpectedStatusCodeError contains the http.Request and http.Response that resulted in this error, therefore an expected non-2xx can always be manually handled/recovered (e.g. a 3xx code redirecting to the HTTPS endpoint).
func JsonRequest ¶ added in v0.17.0
func JsonRequest( ctx context.Context, url *url.URL, httpMethod string, restLiMethod RestLiMethod, contents restlicodec.Marshaler, excludedFields restlicodec.PathSpec, ) (*http.Request, error)
JsonRequest creates an http.Request with the given HTTP method and rest.li method, and populates the body of the request with the given restlicodec.Marshaler contents (see RawJsonRequest)
func RawJsonRequest ¶ added in v0.17.0
func RawJsonRequest(ctx context.Context, url *url.URL, httpMethod string, restLiMethod RestLiMethod, contents io.Reader) (*http.Request, error)
JsonRequest creates an http.Request with the given HTTP method and rest.li method, and populates the body of the request with the given reader
func SetJsonAcceptHeader ¶ added in v0.7.0
func SetJsonContentTypeHeader ¶ added in v0.3.0
func SetRestLiHeaders ¶ added in v0.2.0
func SetRestLiHeaders(req *http.Request, method RestLiMethod)
Types ¶
type BatchMethodError ¶ added in v0.21.0
type BatchMethodError struct { // The contents of the "errors" fields in the batch request's response // TODO: This is a map of the key that caused the error to a message describing the error. Ideally instead of having // raw bytes, each batch method would generate an error handler that correctly deserializes this response Errors []byte // The contents of the "statuses" fields in the batch request's response // TODO: See above, this should also be deserialized into an actual type Statuses []byte // The request that resulted in this error Request *http.Request // The raw response that this error was parsed from Response *http.Response }
BatchMethodError is returned by BATCH_* requests when the "errors" field in the response is present and not null. It contains the raw bytes of said field as its contents are untyped.
func (*BatchMethodError) Error ¶ added in v0.21.0
func (b *BatchMethodError) Error() string
type CreateResponseHasNoEntityHeaderError ¶ added in v0.17.0
CreateResponseHasNoEntityHeaderError is used specifically when a Create request succeeds but the resource implementation does not set the X-RestLi-Id header. This error is recoverable and can be ignored if the response id is not required
func (CreateResponseHasNoEntityHeaderError) Error ¶ added in v0.17.0
func (c CreateResponseHasNoEntityHeaderError) Error() string
type HostnameResolver ¶ added in v0.1.1
type HostnameResolver interface { // ResolveHostnameAndContextForQuery takes in the name of the service for which to resolve the hostname, along with // the URL for the query that is about to be sent. The service name is often the top-level parent resource's name, // but can be any unique identifier for a D2 endpoint. Some HostnameResolver implementations will choose to ignore // this parameter and resolve hostnames using a different strategy. By default, the generated code will always pass // in the top-level parent resource's name. ResolveHostnameAndContextForQuery(serviceName string, query *url.URL) (*url.URL, error) }
type LoggingRoundTripper ¶ added in v0.17.0
type LoggingRoundTripper struct { http.RoundTripper Logger logger }
LoggingRoundTripper is an http.RoundTripper that wraps a backing http.RoundTripper and logs all outbound queries (method, URL, headers and body) to the given logger
type PagingContext ¶ added in v0.25.2
type PagingContext struct { Start *int32 `json:"start,omitempty"` Count *int32 `json:"count,omitempty"` }
func NewPagingContext ¶ added in v0.25.2
func NewPagingContext(start int32, count int32) PagingContext
func (*PagingContext) ComputeHash ¶ added in v0.25.2
func (p *PagingContext) ComputeHash() (hash fnv1a.Hash)
func (*PagingContext) EncodeQueryParams ¶ added in v0.25.2
func (p *PagingContext) EncodeQueryParams() (rawQuery string, err error)
func (*PagingContext) Equals ¶ added in v0.25.2
func (p *PagingContext) Equals(other *PagingContext) bool
func (*PagingContext) EqualsInterface ¶ added in v0.25.2
func (p *PagingContext) EqualsInterface(otherInterface interface{}) bool
type RawRecord ¶ added in v0.25.2
type RawRecord map[string]interface{}
RawRecord is a container for arbitrary data. Because it gets parsed from raw JSON without any extra type information, it is expected that there will be unknown side effects, such as floats turning into integers or vice versa. This is designed to fill the gap for Java's DataMap-backed implementation of rest.li that supports untyped messages. To attempt deserialization into a know/real rest.li object, use the UnmarshalTo method Use at your own risk!
func (*RawRecord) ComputeHash ¶ added in v0.25.2
ComputeHash for a RawRecord always returns the 0-hash
func (*RawRecord) Equals ¶ added in v0.25.2
Equals for a RawRecord always returns false, unless it is being compared with itself
func (*RawRecord) EqualsInterface ¶ added in v0.25.2
EqualsInterface for a RawRecord always returns false, unless it is being compared with itself
func (*RawRecord) MarshalRestLi ¶ added in v0.25.2
func (r *RawRecord) MarshalRestLi(writer restlicodec.Writer) error
func (*RawRecord) UnmarshalRestLi ¶ added in v0.25.2
func (r *RawRecord) UnmarshalRestLi(reader restlicodec.Reader) error
func (*RawRecord) UnmarshalTo ¶ added in v0.25.2
func (r *RawRecord) UnmarshalTo(obj restlicodec.Unmarshaler) error
UnmarshalTo attempts to deserialize this RawRecord into the given object by serializing it first to JSON then calling the given object's unmarshal method
type RestLiClient ¶
type RestLiClient struct { *http.Client HostnameResolver // Whether or not missing fields in a restli response should cause a MissingRequiredFields error to be returned. // Note that even if the error is returned, the response will still be fully deserialized. StrictResponseDeserialization bool }
func (*RestLiClient) Do ¶
Do is a very thin shim between the standard http.Client.Do. All it does it parse the response into a RestLiError if the RestLi error header is set. A non-nil Response with a non-nil error will only occur if http.Client.Do returns such values (see the corresponding documentation). Otherwise, the response will only be non-nil if the error is nil.
func (*RestLiClient) DoActionRequest ¶ added in v0.17.0
func (c *RestLiClient) DoActionRequest(ctx context.Context, url *url.URL, params restlicodec.Marshaler, results restlicodec.Unmarshaler) error
DoActionRequest executes a rest.li Action request and places the given restlicodec.Marshaler in the request's body. Actions with no params are expected to use the EmptyRecord instead. If the given restlicodec.Unmarshaler for the results is non-nil, it will be used to unmarshal the request's body, otherwise the body will be discarded.
func (*RestLiClient) DoAndDecode ¶ added in v0.2.0
func (c *RestLiClient) DoAndDecode(req *http.Request, v restlicodec.Unmarshaler) (*http.Response, error)
DoAndDecode calls Do and attempts to unmarshal the response into the given value. The response body will always be read to EOF and closed, to ensure the connection can be reused.
func (*RestLiClient) DoAndIgnore ¶ added in v0.2.0
DoAndDecode calls Do and drops the response's body. The response body will always be read to EOF and closed, to ensure the connection can be reused.
func (*RestLiClient) DoBatchGetRequest ¶ added in v0.19.0
func (c *RestLiClient) DoBatchGetRequest(ctx context.Context, url *url.URL, resultsReader restlicodec.MapReader) (err error)
func (*RestLiClient) DoCreateRequest ¶ added in v0.17.0
func (c *RestLiClient) DoCreateRequest( ctx context.Context, url *url.URL, create restlicodec.Marshaler, readOnlyFields restlicodec.PathSpec, id restlicodec.Unmarshaler, returnEntity restlicodec.Unmarshaler, ) (err error)
DoCreateRequest executes a rest.li Create request against the given url and places the given restlicodec.Marshaler in the request's body. The X-RestLi-Id header field will be parsed into id (though a CreateResponseHasNoEntityHeaderError will be returned if the header is not set) and if returnEntity is non-nil, it will be used to unmarhsal the body of the response.
func (*RestLiClient) DoDeleteRequest ¶ added in v0.17.0
DoDeleteRequest executes a rest.li Delete request
func (*RestLiClient) DoFinderRequest ¶ added in v0.17.0
func (c *RestLiClient) DoFinderRequest(ctx context.Context, url *url.URL, elements restlicodec.ArrayReader) (total *int, err error)
DoFinderRequest executes a rest.li Finder request and uses the given restlicodec.Unmarshaler to unmarshal the response's body.
func (*RestLiClient) DoGetRequest ¶ added in v0.17.0
func (c *RestLiClient) DoGetRequest(ctx context.Context, url *url.URL, result restlicodec.Unmarshaler) (err error)
DoGetRequest executes a rest.li Get request against the given url and parses the results in the given restlicodec.Unmarshaler
func (*RestLiClient) DoPartialUpdateRequest ¶ added in v0.17.0
func (c *RestLiClient) DoPartialUpdateRequest( ctx context.Context, url *url.URL, patch restlicodec.Marshaler, createAndReadOnlyFields restlicodec.PathSpec, ) error
DoPartialUpdateRequest executes a rest.li Partial Update request and places the given patch objects wrapped in a PartialUpdate in the request's body.
func (*RestLiClient) DoUpdateRequest ¶ added in v0.17.0
func (c *RestLiClient) DoUpdateRequest(ctx context.Context, url *url.URL, update restlicodec.Marshaler) error
DoUpdateRequest executes a rest.li Update request and places the given restlicodec.Marshaler in the request's body.
func (*RestLiClient) FormatQueryUrl ¶
func (c *RestLiClient) FormatQueryUrl(resourceBasename, rawQuery string) (*url.URL, error)
type RestLiError ¶
type RestLiError struct { Message string `json:"message"` ExceptionClass string `json:"exceptionClass"` StackTrace string `json:"stackTrace"` // Will be non-nil if an error occurred when attempting to deserialize the actual JSON response fields (i.e. Status, // Message, ExceptionClass and StackTrace) DeserializationError error `json:"-"` // The request that resulted in this error Request *http.Request `json:"-"` // The raw response that this error was parsed from. Note that to ensure that the connection can be reused, the Body // of the response is fully read into ResponseBody then closed Response *http.Response `json:"-"` ResponseBody []byte `json:"-"` }
RestLiError is returned by the Do* methods when the X-RestLi-Error-Response header is set to true.
func (*RestLiError) Error ¶
func (r *RestLiError) Error() string
type RestLiMethod ¶ added in v0.2.0
type RestLiMethod int
func (RestLiMethod) String ¶ added in v0.7.0
func (i RestLiMethod) String() string
type RestLiObject ¶ added in v0.23.0
type RestLiObject interface { restlicodec.Marshaler restlicodec.Unmarshaler ComputeHash() fnv1a.Hash EqualsInterface(interface{}) bool }
type SimpleHostnameResolver ¶ added in v0.17.0
func (*SimpleHostnameResolver) ResolveHostnameAndContextForQuery ¶ added in v0.17.0
type UnexpectedStatusCodeError ¶ added in v0.17.0
type UnexpectedStatusCodeError struct { // The request that resulted in this error Request *http.Request // The raw response that of the failed call. Note that to ensure that the connection can be reused, the Body // of the response is fully read into ResponseBody then closed Response *http.Response ResponseBody []byte }
UnexpectedStatusCodeError is returned by the Do* methods when the target rest.li service responded with non-2xx code but did not set the expected X-RestLi-Error-Response header.
func (*UnexpectedStatusCodeError) Error ¶ added in v0.17.0
func (u *UnexpectedStatusCodeError) Error() string