jsonapi

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Stringify

func Stringify(v any) string

Types

type Attributes added in v0.0.3

type Attributes[T any] struct {
	// contains filtered or unexported fields
}

func NewAttributes added in v0.0.3

func NewAttributes[T any](v T) Attributes[T]

func (Attributes[T]) JSONAPISerialize added in v0.0.3

func (a Attributes[T]) JSONAPISerialize() (string, error)

type CodeGetter added in v0.0.3

type CodeGetter interface {
	Code() string
}

type Errable added in v0.0.3

type Errable interface {
	ToJSONAPIError() Error
	Error() string
}

func NewInternalServerError added in v0.0.3

func NewInternalServerError(err error) Errable

type Error

type Error struct {
	ID     string
	Status int
	Code   string
	Title  string
	Detail string
}

func NewBadRequest added in v0.0.3

func NewBadRequest(err error) Error

func NewForbidden added in v0.0.3

func NewForbidden(err error) Error

func NewNotFound added in v0.0.3

func NewNotFound(err error) Error

func NewUnauthorized added in v0.0.3

func NewUnauthorized(err error) Error

func (Error) Error added in v0.0.3

func (j Error) Error() string

func (Error) JSONAPISerialize

func (j Error) JSONAPISerialize() (string, error)

type ErrorResponse added in v0.0.3

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

func NewErrorResponse added in v0.0.3

func NewErrorResponse(err error) *ErrorResponse

func (ErrorResponse) Code added in v0.0.3

func (e ErrorResponse) Code() string

func (ErrorResponse) Error added in v0.0.3

func (e ErrorResponse) Error() string

func (ErrorResponse) Title added in v0.0.3

func (e ErrorResponse) Title() string

func (ErrorResponse) ToJSONAPIError added in v0.0.3

func (e ErrorResponse) ToJSONAPIError() Error

type Errors

type Errors []Error

func (Errors) Error added in v0.0.3

func (j Errors) Error() string

func (Errors) JSONAPISerialize

func (j Errors) JSONAPISerialize() (string, error)

type Nil

type Nil struct{}

func (Nil) JSONAPISerialize

func (n Nil) JSONAPISerialize() (string, error)

type Relationship

type Relationship struct {
	Data ResourceIdentifier
}

func (Relationship) JSONAPISerialize

func (j Relationship) JSONAPISerialize() (string, error)

type RelationshipHasMany

type RelationshipHasMany struct {
	Data []ResourceIdentifier
}

func (RelationshipHasMany) JSONAPISerialize

func (j RelationshipHasMany) JSONAPISerialize() (string, error)

type Relationships

type Relationships map[string]Serializer

func (Relationships) JSONAPISerialize

func (j Relationships) JSONAPISerialize() (string, error)

type Resource

type Resource struct {
	ID            string
	Type          string
	Attributes    Serializer
	Relationships Relationships
}

func (Resource) JSONAPISerialize

func (j Resource) JSONAPISerialize() (string, error)

type ResourceIdentifier

type ResourceIdentifier struct {
	ID   string
	Type string
}

func (ResourceIdentifier) JSONAPISerialize

func (j ResourceIdentifier) JSONAPISerialize() (string, error)

type Resourcer

type Resourcer interface {
	ToJSONAPIResource() (data Resource, included Resources)
}

type Resourcers added in v0.0.4

type Resourcers []Resourcer

func (Resourcers) ToJSONAPIResource added in v0.0.4

func (r Resourcers) ToJSONAPIResource() (Resources, Resources)

type Resources

type Resources struct {
	Data []Resource
	// contains filtered or unexported fields
}

func (*Resources) Append

func (j *Resources) Append(r ...Resource)

func (Resources) JSONAPISerialize

func (j Resources) JSONAPISerialize() (string, error)

type Root

type Root[T Serializer] struct {
	Data     T
	Errors   Errors
	Meta     Serializer
	Included Resources
}

func New

func New(data Resource, includes Resources, meta Serializer) (*Root[Resource], error)

func NewErrors

func NewErrors(errors Errors) *Root[Nil]

func NewManyFrom

func NewManyFrom[T Resourcer](list []T, meta Serializer) (*Root[Resources], error)

func (Root[T]) Serialize

func (j Root[T]) Serialize() (string, error)

type Serializer

type Serializer interface {
	JSONAPISerialize() (string, error)
}

type Serializers

type Serializers []Serializer

func (Serializers) JSONAPISerialize

func (s Serializers) JSONAPISerialize() (string, error)

type TitleGetter added in v0.0.3

type TitleGetter interface {
	Title() string
}

Jump to

Keyboard shortcuts

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