Documentation
      ¶
    
    
  
    
  
    Index ¶
- Constants
 - Variables
 - type Codec
 - type Error
 - type FieldAnnotations
 - type LinkOptions
 - type LinkType
 - type MarshalOption
 - type MarshalOptions
 - type Meta
 - type ModelMarshaler
 - type ModelUnmarshaler
 - type MultiError
 - type PaginationLinks
 - type ParameterExtractor
 - type ParameterParser
 - type Payload
 - type PayloadMarshaler
 - type PayloadUnmarshaler
 - type UnmarshalOption
 - type UnmarshalOptions
 
Constants ¶
const ISO8601TimeFormat = "2006-01-02T15:04:05Z"
    ISO8601TimeFormat is the time formatting for the ISO 8601.
const StructTag = "codec"
    StructTag is a constant used as a tag that defines models codecs.
Variables ¶
var ( // ErrCodec is a general codec error. ErrCodec = errors.New("codec") // ErrMarshal is an error with marshaling. ErrMarshal = errors.Wrap(ErrCodec, "marshal") // ErrMarshalPayload is an error of marshaling payload. ErrMarshalPayload = errors.Wrap(ErrMarshal, "payload") // ErrUnmarshal is an error related to unmarshaling process. ErrUnmarshal = errors.Wrap(ErrCodec, "unmarshal") // ErrUnmarshalDocument is an error related to unmarshaling invalid document, ErrUnmarshalDocument = errors.Wrap(ErrUnmarshal, "document") // ErrUnmarshalFieldValue is an error related to unmarshaling field value. ErrUnmarshalFieldValue = errors.Wrap(ErrUnmarshal, "field value") // ErrUnmarshalFieldName is an error related t unmarshaling field name ErrUnmarshalFieldName = errors.Wrap(ErrUnmarshal, "field name") // ErrOptions is an error that defines invalid marshal/unmarshal options. ErrOptions = errors.Wrap(ErrCodec, "options") )
Functions ¶
This section is empty.
Types ¶
type Codec ¶
type Codec interface {
	// MarshalErrors marshals given errors.
	MarshalErrors(w io.Writer, errors ...*Error) error
	// UnmarshalErrors unmarshal provided errors.
	UnmarshalErrors(r io.Reader) (MultiError, error)
	// MimeType returns the mime type that this codec is defined for.
	MimeType() string
}
    Codec is an interface used to marshal and unmarshal data, payload and errors in some encoding type.
type Error ¶
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 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 Meta `json:"meta,omitempty"`
}
    Error is the error structure used for used for codec processes. More info can be found at: 'https://jsonapi.org/format/#errors'
type FieldAnnotations ¶
type FieldAnnotations struct {
	Name        string
	IsHidden    bool
	IsOmitEmpty bool
	Custom      []*mapping.FieldTag
}
    FieldAnnotations is structure that is extracted from the given sField codec specific annotation.
func ExtractFieldAnnotations ¶
func ExtractFieldAnnotations(sField *mapping.StructField, tag, tagSeparator, valuesSeparator string) FieldAnnotations
ExtractFieldAnnotations extracts codec specific tags.
type LinkOptions ¶
type LinkOptions struct {
	// Type defines link type.
	Type LinkType
	// BaseURL should be the common base url for all the links.
	BaseURL string
	// Collection is the link root collection name.
	Collection string
	// RootID is the root collection primary value.
	RootID string
	// RelatedField is the related field name used in the relationship link type.
	RelationField string
}
    LinkOptions contains link options required for marshaling codec data.
type MarshalOption ¶ added in v0.19.0
type MarshalOption func(o *MarshalOptions)
MarshalOption is the option function that sets up the marshal options.
func MarshalSingleModel ¶ added in v0.19.0
func MarshalSingleModel() MarshalOption
MarshalSingleModel marshals the output with single model encoding type.
func MarshalWithLinks ¶ added in v0.19.0
func MarshalWithLinks(links LinkOptions) MarshalOption
MarshalWithLinks marshals the output with provided links
type MarshalOptions ¶
type MarshalOptions struct {
	Link         LinkOptions
	SingleResult bool
}
    MarshalOptions is a structure that contains marshaling information.
type Meta ¶
type Meta map[string]interface{}
Meta is used to represent a `meta` object. http://jsonapi.org/format/#document-meta
type ModelMarshaler ¶
type ModelMarshaler interface {
	// MarshalModels marshal provided models into given codec encoding type. The function should
	// simply encode only provided models without any additional payload like metadata.
	MarshalModels(models []mapping.Model, options ...MarshalOption) ([]byte, error)
	// MarshalModel marshal single models into given codec encoding type.
	MarshalModel(model mapping.Model, options ...MarshalOption) ([]byte, error)
}
    ModelMarshaler is an interface that allows to marshal provided models.
type ModelUnmarshaler ¶
type ModelUnmarshaler interface {
	// UnmarshalModels unmarshals provided data into mapping.Model slice. The data should simply be only encoded models.
	// Requires model or model struct option.
	UnmarshalModels(data []byte, options ...UnmarshalOption) ([]mapping.Model, error)
	// UnmarshalModel unmarshal single model from provided input data. Requires model or model struct option.
	UnmarshalModel(data []byte, options ...UnmarshalOption) (mapping.Model, error)
}
    ModelUnmarshaler is an interface that allows to unmarshal provided models of given model struct.
type MultiError ¶
type MultiError []*Error
MultiError is an error composed of multiple single errors.
func (MultiError) Error ¶
func (m MultiError) Error() string
func (MultiError) Status ¶
func (m MultiError) Status() int
Status gets the most significant api error status.
type PaginationLinks ¶
type PaginationLinks struct {
	// Self should define this page query url.
	Self string `json:"self,omitempty"`
	// First should specify the first page query url.
	First string `json:"first,omitempty"`
	// Prev specify previous page query url.
	Prev string `json:"prev,omitempty"`
	// Next specify next page query url.
	Next string `json:"next,omitempty"`
	// Last specify the last page query url.
	Last string `json:"last,omitempty"`
	// Total defines the total number of the pages.
	Total int64 `json:"total"`
}
    PaginationLinks is the structure that contain options for the pagination links. https://jsonapi.org/examples/#pagination
type ParameterExtractor ¶
type ParameterExtractor interface {
	ExtractParameters(c *core.Controller, q *query.Scope) (query.Parameters, error)
}
    ParameterExtractor is an interface that extracts query parameters from given scope.
type ParameterParser ¶
type ParameterParser interface {
	ParseParameters(c *core.Controller, q *query.Scope, parameters query.Parameters) error
}
    ParameterParser is an interface that parses parameters in given codec format.
type Payload ¶
type Payload struct {
	// Payload defined model structure.
	ModelStruct *mapping.ModelStruct
	// Data contains models data.
	Data []mapping.Model
	// FieldSets is the index based field sets that maps it's indexes with the data.
	FieldSets []mapping.FieldSet
	// Meta is an object containing non-standard meta-data information about the payload.
	Meta Meta
	// IncludedRelations is the information about included relations in the payload.
	IncludedRelations []*query.IncludedRelation
	// PaginationLinks are the links used for pagination.
	PaginationLinks *PaginationLinks
}
    Payload is the default structure used by codecs to marshal and unmarshal.
type PayloadMarshaler ¶
type PayloadMarshaler interface {
	MarshalPayload(w io.Writer, payload *Payload, options ...MarshalOption) error
}
    PayloadMarshaler is the interface used to marshal payload into provided writer..
type PayloadUnmarshaler ¶
type PayloadUnmarshaler interface {
	UnmarshalPayload(r io.Reader, options ...UnmarshalOption) (*Payload, error)
}
    PayloadUnmarshaler is the interface used to unmarshal payload from given reader for provided codec type.
type UnmarshalOption ¶ added in v0.19.0
type UnmarshalOption func(o *UnmarshalOptions)
UnmarshalOption is function that changes unmarshal options.
func UnmarshalStrictly ¶ added in v0.19.0
func UnmarshalStrictly() UnmarshalOption
UnmarshalStrictly is an unmarshal option that sets up option to strictly check the fields when unmarshaled the fields.
func UnmarshalWithModel ¶ added in v0.19.0
func UnmarshalWithModel(model mapping.Model) UnmarshalOption
UnmarshalWithModel is an unmarshal option that sets up model that should be unmarshaled.
func UnmarshalWithModelStruct ¶ added in v0.19.0
func UnmarshalWithModelStruct(modelStruct *mapping.ModelStruct) UnmarshalOption
UnmarshalWithModelStruct is an unmarshal option that sets up model struct that should be unmarshaled.
func UnmarshalWithSingleExpectation ¶ added in v0.19.0
func UnmarshalWithSingleExpectation() UnmarshalOption
UnmarshalWithSingleExpectation is an unmarshal option that sets up the single model unmarshal expectation.
type UnmarshalOptions ¶
type UnmarshalOptions struct {
	StrictUnmarshal, ExpectSingle bool
	ModelStruct                   *mapping.ModelStruct
	Model                         mapping.Model
}
    UnmarshalOptions is the structure that contains unmarshal options. UnmarshalOptions requires model or model struct to be defined.