Documentation ¶
Overview ¶
Package client represents API error interface accessors for the SDK.
Index ¶
- func ParseCollection(b []byte) ([]map[string]interface{}, error)
- func ParseObject(b []byte) (map[string]interface{}, error)
- func SprintError(code, message, extra string, origErr error) string
- type BatchError
- type BatchedErrors
- type Client
- type Error
- type GetOptions
- type ID
- type Object
- type OutputMode
- type Query
- type QueryOperator
- type RESTRequest
- type RequestFailure
- type Service
- type URLBuilder
- type UnmarshalError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseCollection ¶
ParseCollection parses JSON bytes to a slice of generic maps
func ParseObject ¶
ParseObject parses JSON bytes to a generic map
func SprintError ¶
SprintError returns a string of the formatted error code.
Both extra and origErr are optional. If they are included their lines will be added, but if they are not included their lines will be ignored.
Types ¶
type BatchError ¶
type BatchedErrors ¶
type BatchedErrors interface { // Satisfy the base Error interface. Error // Returns the original error if one was set. Nil is returned if not set. OrigErrs() []error }
BatchedErrors is a batch of errors which also wraps lower level errors with code, message, and original errors. Calling Error() will include all errors that occurred in the batch.
Replaces BatchError
func NewBatchError ¶
func NewBatchError(code, message string, errs []error) BatchedErrors
NewBatchError returns an BatchedErrors with a collection of errors as an array of errors.
type Client ¶
type Client interface { // Returns the configured URL address Address() string // Get retrieves all data for a single Object Get(id ID, opts *GetOptions) (map[string]interface{}, Error) // GetURL retrieves data from a URL path GetURL(service Service, urlPath string) ([]byte, int, Error) // GetURLWithID is used to call a custom REST endpoint GetURLWithID(id ID, urlPath string) ([]byte, int, Error) // GetRelationID retrieves a single relation ID of an object, by name GetRelationID(id ID, path string) (ID, Error) // GetRelation retrieves a single relation of an object, by name GetRelation(id ID, path string) (map[string]interface{}, Error) // GetDescendents retrieves all descendents that match a relation name or a model type GetDescendants(id ID, path string, opts *GetOptions) ([]map[string]interface{}, Error) // GetDescendent retrieves as single descendents that matches a relation name or a model type GetDescendant(id ID, path string, opts *GetOptions) (map[string]interface{}, Error) // GetAll retrieves a list of objects. The service and modelIndex are required. // Additional options, like which fields to retrieve and a query to filter // results, can be passed using opts. GetCollection(service Service, modelIndex string, opts *GetOptions) ([]map[string]interface{}, Error) // QueryByName is a convinience method that queries a service collection to find // an object by its 'name' attribute. If a matching object is found, its ID is // returned. QueryByName(service Service, modelIndex, name string) (ID, Error) // QueryById is a convinience method that queries a service collection to find // an object by its 'id' attribute. If a matching object is found, its ID is // returned. QueryById(service Service, modelIndex, id string) (ID, Error) // WaitForState queries a state and returns when it matches the specified value // or maxTime is reached WaitForState(id ID, fieldIndex string, value interface{}, maxTime time.Duration, msg string) Error // WaitForStates is similar WaitForState but checks multiple states and returns the matched state WaitForStates(id ID, fieldIndex string, values []interface{}, maxTime time.Duration, msg string) (interface{}, Error) // Post is used to create a new model object. Post(rr *RESTRequest) (map[string]interface{}, Error) // Post is used to create a new model object. The contentType is assumed to be JSON. The queryParams is optional. PostFromJSON(service Service, path string, jsonMap map[string]interface{}, queryParams map[string]string) (map[string]interface{}, Error) // Post is used to create resources or call a custom REST endpoint. The contentType is assumed to be YAML. // The path and queryParams are optional PostWithID(id ID, path string, data []byte, queryParams map[string]string) (map[string]interface{}, Error) // PutWithIDFromJSON is used to modify a model object with attributes in a JSON map PutWithIDFromJSON(id ID, jsonMap map[string]interface{}) (map[string]interface{}, Error) // Put is used to modify a model object. Put(rr *RESTRequest) (map[string]interface{}, Error) // Delete is used to delete a resource Delete(id ID, params map[string]string) Error // DeleteURL is used to delete a resource identified by the URL DeleteURL(service Service, url string) Error // Options is used to execute an HTTP OPTIONS request Options(service Service, url string) (map[string]interface{}, Error) }
Client provides access to the Nirmata REST API
type Error ¶
type GetOptions ¶
type GetOptions struct { Fields []string Filter Query Mode OutputMode }
GetOptions contains optional paramameters used when retrieving objects
func NewGetModelID ¶
func NewGetModelID(fields []string, query Query) *GetOptions
NewGetModelID builds a new GetOptions instance with Model ID attribute and supplied fields
func NewGetOptions ¶
func NewGetOptions(fields []string, query Query) *GetOptions
NewGetOptions build a new GetOptions instance
type ID ¶
type ID interface { Service() Service ModelIndex() string UUID() string Map() map[string]interface{} }
ID identifies a model object
func ParseIDFromMap ¶
ParseIDFromMap parses a JSON data map to an ID
type Object ¶
type Object interface { ID() ID Data() map[string]interface{} GetString(name string) string GetRelation(name string) (ID, error) GetRelations(name string) ([]ID, error) }
Object has an unique ID, attributes, and relations
type OutputMode ¶
type OutputMode int
OutputMode sets the output mode for a REST API call
const ( // OutputModeNone ... OutputModeNone OutputMode = iota + 1 // OutputModeDefault ... OutputModeDefault // OutputModeExport ... OutputModeExport // OutputModeExportDetails ... OutputModeExportDetails )
type QueryOperator ¶
type QueryOperator int
QueryOperator provides boolean and arithmetic operators for field-value pairs
const ( // QueryOperatorEquals ... QueryOperatorEquals QueryOperator = iota + 1 )
type RESTRequest ¶
type RESTRequest struct { Service Service Method string Headers map[string]string Path string Data []byte ContentType string QueryParams map[string]string }
RESTRequest is used to pass HTTP Request parameters
type RequestFailure ¶
type RequestFailure interface { Error // The status code of the HTTP response. StatusCode() int // The request ID returned by the service for a request failure. This will // be empty if no request ID is available such as the request failed due // to a connection error. RequestID() string }
A RequestFailure is an interface to extract request failure information from an Error such as the request ID of the failed request returned by a service. RequestFailures may not always have a requestID value if the request failed prior to reaching the service such as a connection error.
func NewRequestFailure ¶
func NewRequestFailure(err Error, statusCode int, reqID string) RequestFailure
NewRequestFailure returns a wrapped error with additional information for request status code, and service requestID.
Should be used to wrap all request which involve service requests. Even if the request failed without a service response, but had an HTTP status code that may be meaningful.
type Service ¶
type Service int
Service is an enumeration type for available services
func ParseService ¶
ParseService converts a string to a service
type URLBuilder ¶
type URLBuilder interface { ToService(s Service) URLBuilder WithPath(path string) URLBuilder WithPaths(paths ...string) URLBuilder WithQuery(q Query) URLBuilder WithParameters(params map[string]string) URLBuilder WithMode(m OutputMode) URLBuilder SelectFields(fields []string) URLBuilder Build() string }
URLBuilder helps build a URL for the Nirmata REST API
func NewURLBuilder ¶
func NewURLBuilder(address string) URLBuilder
NewURLBuilder creates a new URLBuilder
type UnmarshalError ¶
type UnmarshalError interface { Bytes() []byte // contains filtered or unexported methods }
UnmarshalError provides the interface for the SDK failing to unmarshal data.
func NewUnmarshalError ¶
func NewUnmarshalError(err error, msg string, bytes []byte) UnmarshalError
NewUnmarshalError returns an initialized UnmarshalError error wrapper adding the bytes that fail to unmarshal to the error.