jsonapi

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MediaType is the identifier for the JSON API media type
	// see http://jsonapi.org/format/#document-structure
	MediaType = "application/vnd.api+json"

	// ISO8601TimeFormat is the time formatting for the ISO 8601.
	ISO8601TimeFormat = "2006-01-02T15:04:05Z"
)

Variables

This section is empty.

Functions

func Marshal

func Marshal(w io.Writer, v interface{}) error

Marshal marshals the provided value 'v' into the writer with the jsonapi encoding. Takes the default controller for the model mapping.

func MarshalC

func MarshalC(c *ctrl.Controller, w io.Writer, v interface{}) error

MarshalC marshals the provided value 'v' into the writer. It uses the 'c' controller

func MarshalErrors

func MarshalErrors(w io.Writer, errs ...*Error) error

MarshalErrors writes a JSON API response using the given `[]error`.

For more information on JSON API error payloads, see the spec here: http://jsonapi.org/format/#document-top-level and here: http://jsonapi.org/format/#error-objects.

func MarshalScope

func MarshalScope(w io.Writer, s *query.Scope) error

MarshalScope marshals the scope into the selceted writer for the given controller

func MarshalScopeC

func MarshalScopeC(c *ctrl.Controller, w io.Writer, s *query.Scope) error

MarshalScopeC marshals the scope into the selceted writer for the given controller

func Unmarshal

func Unmarshal(r io.Reader, v interface{}) error

Unmarshal unmarshals the incoming reader stream into provided value 'v'. The model of the value 'v' should already be registered in the default controller.

func UnmarshalC

func UnmarshalC(c *ctrl.Controller, r io.Reader, v interface{}) error

UnmarshalC unmarshals the incoming reader stream 'r' into provided model 'v' assuming that it is already registered within the controller 'c'

func UnmarshalManyScope

func UnmarshalManyScope(r io.Reader, model interface{}) (*query.Scope, error)

UnmarshalManyScope unmarshals the scope of multiple values for the default controller and given model struct. Provided model argument may be a value of the slice of models i.e. &[]*Model{} or a mapping.ModelStruct.

func UnmarshalManyScopeC

func UnmarshalManyScopeC(c *ctrl.Controller, r io.Reader, model interface{}) (*query.Scope, error)

UnmarshalManyScopeC unmarshals the scope of multiple values for the given controller and model struct. Provided model argument may be a value of the slice of models i.e. &[]*Model{} or a mapping.ModelStruct.

func UnmarshalSingleScope

func UnmarshalSingleScope(r io.Reader, model interface{}) (*query.Scope, error)

UnmarshalSingleScope unmarshals the value from the reader and creates the scope for the default controller. Provided model argument may be a value of the Model i.e. &Model{} or a mapping.ModelStruct.

func UnmarshalSingleScopeC

func UnmarshalSingleScopeC(c *ctrl.Controller, r io.Reader, model interface{}) (*query.Scope, error)

UnmarshalSingleScopeC unmarshals the value from the reader and creates new scope. Provided model argument may be a value of the Model i.e. &Model{} or a mapping.ModelStruct.

func UnmarshalWithSelected

func UnmarshalWithSelected(r io.Reader, v interface{}) ([]*mapping.StructField, error)

UnmarshalWithSelected unmarshals the value from io.Reader and returns the selected fields if the value is a single.

func UnmarshalWithSelectedC

func UnmarshalWithSelectedC(c *controller.Controller, r io.Reader, v interface{}) ([]*mapping.StructField, error)

UnmarshalWithSelectedC unmarshals the value from io.Reader and returns the selected fields if the value is a single.

Types

type Error added in v0.2.1

type Error struct {
	// ID is a unique identifier for this particular occurrence of a problem.
	ID string `json:"id,omitempty"`

	// Title is a short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization.
	Title string `json:"title,omitempty"`

	// Detail is a human-readable explanation specific to this occurrence of the problem. Like title, this field’s value can be localized.
	Detail string `json:"detail,omitempty"`

	// Status is the HTTP status code applicable to this problem, expressed as a string value.
	Status string `json:"status,omitempty"`

	// Code is an application-specific error code, expressed as a string value.
	Code string `json:"code,omitempty"`

	// Meta is an object containing non-standard meta-information about the error.
	Meta map[string]interface{} `json:"meta,omitempty"`
}

Error is the jsonapi error structure. It is used for marshaling and unmarshaling purpose. More info can be found at: 'https://jsonapi.org/format/#errors'

type ErrorsPayload

type ErrorsPayload struct {
	Errors []*Error `json:"errors"`
}

ErrorsPayload is a serializer struct for representing a valid JSON API errors payload.

type Link struct {
	Href string `json:"href"`
	Meta Meta   `json:"meta,omitempty"`
}

Link is used to represent a member of the `links` object.

type Linkable

type Linkable interface {
	JSONAPILinks() *Links
}

Linkable is used to include document links in response data e.g. {"self": "http://example.com/posts/1"}

type Links map[string]interface{}

Links is used to represent a `links` object. http://jsonapi.org/format/#document-links

type Meta

type Meta map[string]interface{}

Meta is used to represent a `meta` object. http://jsonapi.org/format/#document-meta

type Metable

type Metable interface {
	JSONAPIMeta() *Meta
}

Metable is used to include document meta in response data e.g. {"foo": "bar"}

type RelationshipLinkable

type RelationshipLinkable interface {
	// JSONAPIRelationshipLinks will be invoked for each relationship with the corresponding relation name (e.g. `comments`)
	JSONAPIRelationshipLinks(relation string) *Links
}

RelationshipLinkable is used to include relationship links in response data e.g. {"related": "http://example.com/posts/1/comments"}

type RelationshipMetable

type RelationshipMetable interface {
	// JSONRelationshipMeta will be invoked for each relationship with the corresponding relation name (e.g. `comments`)
	JSONAPIRelationshipMeta(relation string) *Meta
}

RelationshipMetable is used to include relationship meta in response data

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL