Documentation ¶
Overview ¶
Package resource rest-ish-ly provides game data similar to http://jsonapi.org.
Index ¶
- type Dict
- type Document
- type DocumentBuilder
- func (build DocumentBuilder) AddError(err error) DocumentBuilder
- func (build DocumentBuilder) AddObject(obj *Object)
- func (build DocumentBuilder) NewIncludes() ObjectList
- func (build DocumentBuilder) NewObject(id, class string) *Object
- func (build DocumentBuilder) NewObjects() ObjectsBuilder
- func (build DocumentBuilder) SetIncluded(objects ObjectList) DocumentBuilder
- func (build DocumentBuilder) SetLink(key string, link Link) DocumentBuilder
- func (build DocumentBuilder) SetMeta(key string, value interface{}) DocumentBuilder
- func (build DocumentBuilder) Sets(objects ObjectList) DocumentBuilder
- type Error
- type IBuildObjects
- type IResource
- type Link
- type Links
- type MultiDocument
- type Object
- type ObjectBuilder
- type ObjectDocument
- type ObjectList
- type ObjectsBuilder
- type PathError
- type Relationship
- type Wrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Document ¶
type Document struct { // data can either be an Object or an array of Objects // (the lack of omitempty vs omitnil is super-annoying.) Data interface{} `json:"data"` Errors []Error `json:"error,omitempty"` Meta Dict `json:"meta,omitempty"` Included []*Object `json:"included,omitempty"` Links Links `json:"links,omitempty"` }
Document provides json-data roughly following the description at http://jsonapi.org/format/#document-structure. DocumentBuilder provides an API for generating these structures properly.
type DocumentBuilder ¶
type DocumentBuilder struct {
// contains filtered or unexported fields
}
DocumentBuilder provides an api for creating json-api document structures.
func NewDocumentBuilder ¶
func NewDocumentBuilder(doc *Document) DocumentBuilder
NewDocumentBuilder creates an api-object to hepl populate the passed document.
func (DocumentBuilder) AddError ¶
func (build DocumentBuilder) AddError(err error) DocumentBuilder
AddError appends an error to the list of errors included by this document. NOTE: if ever needed, could return or take error builder to which the other bits of the jsonapi error structure could be added
func (DocumentBuilder) AddObject ¶
func (build DocumentBuilder) AddObject(obj *Object)
func (DocumentBuilder) NewIncludes ¶
func (build DocumentBuilder) NewIncludes() ObjectList
NewIncludes returns a builder which can add objects (or object identifiers) to a compound document.
func (DocumentBuilder) NewObject ¶
func (build DocumentBuilder) NewObject(id, class string) *Object
NewObject sets the document data to the passed object identifier. Returns an object builder to populate data about the identified object.
func (DocumentBuilder) NewObjects ¶
func (build DocumentBuilder) NewObjects() ObjectsBuilder
NewObjects returns a builder to add an array of objects ( or object identifiers ) to the document.
func (DocumentBuilder) SetIncluded ¶
func (build DocumentBuilder) SetIncluded(objects ObjectList) DocumentBuilder
SetIncluded sets the document's compound/include data to the passed object list. ( To comply with jsonapi, objects in the list should be referenced by the primary object. )
func (DocumentBuilder) SetLink ¶
func (build DocumentBuilder) SetLink(key string, link Link) DocumentBuilder
SetLink to add the named link to the document's list of links.
func (DocumentBuilder) SetMeta ¶
func (build DocumentBuilder) SetMeta(key string, value interface{}) DocumentBuilder
SetMeta to add a key-value the document's metadata.
func (DocumentBuilder) Sets ¶
func (build DocumentBuilder) Sets(objects ObjectList) DocumentBuilder
Sets the document data to an existing array of objects or object identifiers. Returns a builder to add objects to that array.
type Error ¶
type Error struct { //Id string `json:"id,omitempty"` // status, code, title, detail, // links, source, Code string `json:"meta,omitempty"` }
type IBuildObjects ¶
DocumentBuilder, ObjectsBuilder, and ObjectList satisfy this interface, which allows for either one object or multiple objects to be added depending on the context.
type IResource ¶
type IResource interface { // Return the named sub-resource Find(string) (IResource, bool) // Return the resource Query() Document // Post to the resource Post(io.Reader) (Document, error) }
IResource interfaces with a rest-ish endpoint. See also, Wrapper, which provides a function-based adapter.
type MultiDocument ¶
type MultiDocument struct { Data []Object `json:"data"` Meta Dict `json:"meta,omitempty"` Included []Object `json:"included,omitempty"` }
for deserializing
type Object ¶
type Object struct { Id string `json:"id,omitempty"` Class string `json:"type,omitempty"` Attributes Dict `json:"attributes,omitempty"` Relationships map[string]Relationship `json:"relationships,omitempty"` Meta Dict `json:"meta,omitempty"` }
type ObjectBuilder ¶
type ObjectBuilder struct {
Object *Object
}
func (*ObjectBuilder) AddObject ¶
func (o *ObjectBuilder) AddObject(obj *Object)
func (*ObjectBuilder) NewObject ¶
func (o *ObjectBuilder) NewObject(id, class string) *Object
type ObjectDocument ¶
type ObjectDocument struct { Data Object `json:"data"` Meta Dict `json:"meta,omitempty"` Included []Object `json:"included,omitempty"` }
for deserializing
type ObjectList ¶
type ObjectList struct {
// contains filtered or unexported fields
}
By default the object list does not have storage. An empty list acts as a "null device".
func (ObjectList) AddObject ¶
func (l ObjectList) AddObject(obj *Object)
func (ObjectList) NewObject ¶
func (l ObjectList) NewObject(id, class string) *Object
Add an object identifier to the list of document objects. Returns a builder to turn the identifier into a full object.
func (ObjectList) Objects ¶
func (l ObjectList) Objects() (ret []*Object)
Return the array of added objects, if any.
type ObjectsBuilder ¶
type ObjectsBuilder struct {
// contains filtered or unexported fields
}
func (ObjectsBuilder) AddObject ¶
func (o ObjectsBuilder) AddObject(obj *Object)
func (ObjectsBuilder) NewObject ¶
func (o ObjectsBuilder) NewObject(id, class string) *Object
Add an object identifier to the list of document objects. Return a builder to turn the identifier into a full object.
type Relationship ¶
type Relationship struct { // data can either be an Object or an array of Objects // (the lack of omitempty vs omitnil is super-annoying.) Data interface{} `json:"data,omitempty"` Meta Dict `json:"meta,omitempty"` }
type Wrapper ¶
type Wrapper struct { Finds func(string) (IResource, bool) Queries func(DocumentBuilder) Posts func(io.Reader, DocumentBuilder) error }
Turn one or more IResource compatible functions into a full interface implementation.