Documentation
¶
Index ¶
- Constants
- func Marshal(v interface{}, p *MarshalParams) ([]byte, error)
- func MarshalErrors(p *MarshalParams, errs ...Error) ([]byte, error)
- func RegisterMarshaler(t reflect.Type, u marshalerFunc)
- func RegisterUnmarshaler(t reflect.Type, u unmarshalerFunc)
- func Respond(w http.ResponseWriter, r *http.Request, statusCode int, v interface{}, ...) error
- func RespondError(w http.ResponseWriter, r *http.Request, statusCode int, p *MarshalParams, ...) error
- func SetJSONIndent(indent string)
- func SetJSONPrefix(prefix string)
- func SetTagKey(key string)
- func Unmarshal(data []byte, v interface{}) error
- type Attributes
- type CompoundDocument
- type CompoundRelationship
- type Document
- type Error
- type Information
- type Links
- type MarshalParams
- type Meta
- type NewCompoundDocumentParams
- type NewDocumentParams
- type Relationship
- type RelationshipLink
- type Relationships
- type Resource
Constants ¶
const ContentType = "application/vnd.api+json"
ContentType is the required Content-Type header value for JSON:API request documents. See https://jsonapi.org/format/#content-negotiation-clients.
Variables ¶
This section is empty.
Functions ¶
func Marshal ¶
func Marshal(v interface{}, p *MarshalParams) ([]byte, error)
Marshal returns the JSON:API encoding of v.
func MarshalErrors ¶
func MarshalErrors(p *MarshalParams, errs ...Error) ([]byte, error)
MarshalErrors returns the JSON:API errors encoding of errs.
func RegisterMarshaler ¶
RegisterMarshaler register a custom marshaller function for a t type.
func RegisterUnmarshaler ¶
RegisterUnmarshaler register a new unmarshaler function for type t.
func Respond ¶
func Respond(w http.ResponseWriter, r *http.Request, statusCode int, v interface{}, p *MarshalParams) error
Respond encodes v in to a JSON:API object and writes it to the body of response w. It also sets statusCode as the response status code.
func RespondError ¶
func RespondError(w http.ResponseWriter, r *http.Request, statusCode int, p *MarshalParams, errs ...Error) error
RespondError encodes v in to a JSON:API error object and writes it to the body of response w. It also sets statusCode as the response status code.
func SetJSONIndent ¶
func SetJSONIndent(indent string)
SetJSONIndent sets the indent value for json.MarshalIndent. See // See https://golang.org/pkg/encoding/json/#MarshalIndent.
func SetJSONPrefix ¶
func SetJSONPrefix(prefix string)
SetJSONPrefix sets the prefix value for json.MarshalIndent. See https://golang.org/pkg/encoding/json/#MarshalIndent.
Types ¶
type Attributes ¶
type Attributes map[string]interface{}
Attributes is a JSON:API document resource attributes object. See https://jsonapi.org/format/#document-resource-object-attributes.
type CompoundDocument ¶
type CompoundDocument struct {
Data []*Resource `json:"data"`
// contains filtered or unexported fields
}
CompoundDocument represents a compound document's top-level object. See https://jsonapi.org/format/#document-compound-documents.
func NewCompoundDocument ¶
func NewCompoundDocument(p *NewCompoundDocumentParams) *CompoundDocument
NewCompoundDocument generates a new compound top-level document object.
type CompoundRelationship ¶
type CompoundRelationship struct {
Data []*Resource `json:"data"`
// contains filtered or unexported fields
}
CompoundRelationship is a JSON:API compound relationship object. See https://jsonapi.org/format/#document-resource-object-relationships.
func NewCompoundRelationship ¶
func NewCompoundRelationship() *CompoundRelationship
NewCompoundRelationship generates a new JSON:API compound relationship object.
type Document ¶
type Document struct {
Data *Resource `json:"data,omitempty"`
// contains filtered or unexported fields
}
Document is a JSON:API document top-level object. See https://jsonapi.org/format/#document-top-level.
func NewDocument ¶
func NewDocument(p *NewDocumentParams) *Document
NewDocument generates a new top-level document object.
type Error ¶
type Error struct {
ID string `json:"id,omitempty"`
Links Links `json:"links,omitempty"`
Status string `json:"status,omitempty"`
Code string `json:"code,omitempty"`
Title string `json:"title,omitempty"`
Detail string `json:"detail,omitempty"`
Source map[string]string `json:"source,omitempty"`
Meta Meta `json:"meta,omitempty"`
}
Error is a JSON:API error object. See https://jsonapi.org/format/#error-objects.
type Information ¶
type Information struct {
Version string `json:"version,omitempty"`
Meta Meta `json:"meta,omitempty"`
}
Information is an object that holds information about the JSON:API implementation a the top-level document. See https://jsonapi.org/format/#document-jsonapi-object.
type Links ¶
type Links map[string]interface{}
Links is a JSON:API links object. See https://jsonapi.org/format/#document-links.
func (Links) AddLinkWithMeta ¶
AddLinkWithMeta adds a link with a meta object.
type MarshalParams ¶
MarshalParams are the optional parameters to add links and meta objects to a top-level document.
type Meta ¶
type Meta map[string]interface{}
Meta is a JSON:API meta object. See https://jsonapi.org/format/#document-meta.
type NewCompoundDocumentParams ¶
type NewCompoundDocumentParams struct {
// contains filtered or unexported fields
}
NewCompoundDocumentParams are the parameters describing a new compound top-level document.
type NewDocumentParams ¶
type NewDocumentParams struct {
// contains filtered or unexported fields
}
NewDocumentParams are the parameters describing a top-level document.
type Relationship ¶
type Relationship struct {
Data *Resource `json:"data"`
// contains filtered or unexported fields
}
Relationship struct { is a JSON:API relationship object. See https://jsonapi.org/format/#document-resource-object-relationships.
func NewRelationship ¶
func NewRelationship() *Relationship
NewRelationship generates a new JSON:API relationship object.
func (*Relationship) AddResource ¶
func (r *Relationship) AddResource(resource *Resource)
AddResource adds a new resource to an existing realationship.
type RelationshipLink ¶
type RelationshipLink struct {
Self string `json:"self,omitempty"`
Related string `json:"related,omitempty"`
}
RelationshipLink is a JSON:API relationship links object. See https://jsonapi.org/format/#document-resource-object-related-resource-links.
type Relationships ¶
type Relationships map[string]interface{}
Relationships is a map of JSON:API relationship objects.
type Resource ¶
type Resource struct {
// Exception: The id member is not required when the resource object originates at the client and represents a new resource to be created on the server.
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Attributes Attributes `json:"attributes,omitempty"`
Relationships Relationships `json:"relationships,omitempty"`
Links Links `json:"links,omitempty"`
Meta Meta `json:"meta,omitempty"`
}
Resource is a JSON:API resource object. See https://jsonapi.org/format/#document-resource-objects.
func NewResource ¶
func NewResource() *Resource
NewResource generates a new JSON:API resource object.
func (*Resource) SetIDAndType ¶
SetIDAndType sets the id and type of a JSON:API resource object. TODO warn or error out when ID isn't plural?