core

package module
v0.0.0-...-63c902a Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2021 License: MIT Imports: 5 Imported by: 3

README

go-jsonapi-core

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AssertionFailure = fmt.Errorf("type assertion failed")

Functions

This section is empty.

Types

type Collection

type Collection []Resource

type Document

type Document struct {
	JSONAPI  *Implementation        `json:"jsonapi,omitempty"`
	Data     interface{}            `json:"data,omitempty"`
	Meta     map[string]interface{} `json:"meta,omitempty"`
	Links    LinksObject            `json:"links,omitempty"`
	Included Included               `json:"included,omitempty"`
	Errors   []Error                `json:"errors,omitempty"`
}

func New

func New() Document

func (*Document) AssertDataType

func (d *Document) AssertDataType() error

func (*Document) ContentLength

func (d *Document) ContentLength() int

func (*Document) PopIncluded

func (d *Document) PopIncluded() Included

func (Document) Size

func (d Document) Size() int

func (*Document) Version

func (d *Document) Version()

type Error

type Error struct {
	Error      error                  `json:"-"`
	Identifier string                 `json:"id,omitempty"`
	Links      *LinksObject           `json:"links,omitempty"`
	Status     string                 `json:"status,omitempty"`
	Code       string                 `json:"code,omitempty"`
	Title      string                 `json:"title,omitempty"`
	Detail     string                 `json:"detail,omitempty"`
	Source     *SourceObject          `json:"source,omitempty"`
	Meta       map[string]interface{} `json:"meta,omitempty"`
}

func MakeError

func MakeError(status int) *Error

type Implementation

type Implementation struct {
	Version string                 `json:"version,omitempty"`
	Meta    map[string]interface{} `json:"meta,omitempty"`
}

type Included

type Included []Resource

func (Included) Find

func (i Included) Find(r Resource) (*Resource, bool)

func (Included) FindIndex

func (i Included) FindIndex(r Resource) (int, bool)

func (Included) Merge

func (i Included) Merge(c Included) Included

func (Included) MergeResource

func (i Included) MergeResource(r Resource) Included

Merge a resource into the collection, such as for `Included`

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

type LinksObject

type LinksObject map[string]interface{}

type Resource

type Resource struct {
	Identifier    string                 `json:"id,omitempty"`
	Type          string                 `json:"type"`
	Attributes    map[string]interface{} `json:"attributes,omitempty"`
	Meta          map[string]interface{} `json:"meta,omitempty"`
	Relationships map[string]Document    `json:"relationships,omitempty"`
	// Links         map[string]string      `json:"links,omitempty"`
	Links LinksObject `json:"links,omitempty"`
}

func (Resource) Identify

func (r Resource) Identify() Resource

type SourceObject

type SourceObject struct {
	Pointer   string `json:"pointer,omitempty"`
	Parameter string `json:"parameter,omitempty"`
}

Jump to

Keyboard shortcuts

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