jsonapi

package
v0.0.0-...-f3ad2b4 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2015 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SerializeModel

func SerializeModel(backend db.Backend, m kit.Model) (*ApiModel, []*ApiModel, apperror.Error)

func SerializeModels

func SerializeModels(backend db.Backend, models []kit.Model) ([]*ApiModel, []*ApiModel, apperror.Error)

Types

type ApiData

type ApiData struct {
	Data     interface{}            `json:"data"`
	Included []*ApiModel            `json:"included,omitempty"`
	Meta     map[string]interface{} `json:"meta,omitempty"`
	Errors   []*ApiError            `json:"errors,omitempty"`
}

func (*ApiData) AddError

func (d *ApiData) AddError(errs ...apperror.Error)

func (*ApiData) AddIncludedModel

func (d *ApiData) AddIncludedModel(s *Serializer, models ...kit.Model) apperror.Error

func (*ApiData) AddModel

func (d *ApiData) AddModel(s *Serializer, models ...kit.Model) apperror.Error

func (*ApiData) ReduceIncludedDuplicates

func (d *ApiData) ReduceIncludedDuplicates()

func (*ApiData) ToMap

func (d *ApiData) ToMap() (map[string]interface{}, apperror.Error)

type ApiError

type ApiError struct {
	Code    string `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
}

func SerializeError

func SerializeError(err error) []*ApiError

type ApiModel

type ApiModel struct {
	Type          string                            `json:"type"`
	Id            string                            `json:"id"`
	Attributes    map[string]interface{}            `json:"attributes,omitempty"`
	Relationships map[string]map[string]interface{} `json:"relationships,omitempty"`
}

func ApiModelFromMap

func ApiModelFromMap(rawData interface{}) (*ApiModel, apperror.Error)

func ApiModelsFromData

func ApiModelsFromData(data interface{}) ([]*ApiModel, bool, apperror.Error)

func (*ApiModel) AddRelation

func (d *ApiModel) AddRelation(name string, data *ApiModel, isSingle bool)

func (*ApiModel) GetRelation

func (d *ApiModel) GetRelation(name string) ([]*ApiModel, bool, apperror.Error)

func (ApiModel) GetRelations

func (d ApiModel) GetRelations() (map[string][]*ApiModel, apperror.Error)

type ApiModelData

type ApiModelData struct {
	ApiData
	Data *ApiModel `json:"data,omitempty"`
}

type ApiModelsData

type ApiModelsData struct {
	ApiData
	Data []*ApiModel `json:"data,omitempty"`
}

type Serializer

type Serializer struct {
	// contains filtered or unexported fields
}

func New

func New(backends map[string]db.Backend) *Serializer

func (*Serializer) MustSerializeResponse

func (s *Serializer) MustSerializeResponse(response kit.Response) (interface{}, apperror.Error)

func (*Serializer) Name

func (s *Serializer) Name() string

func (*Serializer) SerializeModel

func (s *Serializer) SerializeModel(model kit.Model) (interface{}, []interface{}, apperror.Error)

SerializeModel converts a model into the target format.

func (*Serializer) SerializeResponse

func (s *Serializer) SerializeResponse(response kit.Response) (interface{}, apperror.Error)

SerializeResponse converts a response with model data into the target format.

func (*Serializer) SerializeTransferData

func (s *Serializer) SerializeTransferData(transData kit.TransferData) (interface{}, apperror.Error)

func (*Serializer) UnserializeModel

func (s *Serializer) UnserializeModel(collection string, rawData interface{}) (kit.Model, apperror.Error)

func (*Serializer) UnserializeRequest

func (s *Serializer) UnserializeRequest(rawData interface{}, request kit.Request) apperror.Error

UnserializeRequest converts request data into a request object.

func (*Serializer) UnserializeTransferData

func (s *Serializer) UnserializeTransferData(rawData interface{}) (kit.TransferData, apperror.Error)

Jump to

Keyboard shortcuts

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