response

package
v0.0.0-...-98a7bba Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultLimit = 15

Variables

This section is empty.

Functions

func EncodeError

func EncodeError(w http.ResponseWriter, err error)

Types

type BadRequestError

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

func NewBadRequestError

func NewBadRequestError(msg string) BadRequestError

func (BadRequestError) Error

func (e BadRequestError) Error() string

type Collection

type Collection struct {
	Data  any             `json:"data"`
	Links CollectionLinks `json:"links"`
}

func (Collection) Validate

func (c Collection) Validate() error
type CollectionLinks struct {
	Self Link  `json:"self"`
	Prev *Link `json:"prev,omitempty"`
	Next *Link `json:"next,omitempty"`
}

type Error

type Error struct {
	Status int    `json:"status"`
	Code   string `json:"code,omitempty"`
	Title  string `json:"title"`
	Detail string `json:"detail,omitempty"`
}

type InternalServerError

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

func NewInternalServerError

func NewInternalServerError(msg string) InternalServerError

func (InternalServerError) Error

func (e InternalServerError) Error() string
type Link struct {
	Href  string   `json:"href,omitempty"`
	Title string   `json:"title,omitempty"`
	Meta  LinkMeta `json:"meta,omitempty"`
}

type LinkBuilder

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

func NewLinkBuilder

func NewLinkBuilder() *LinkBuilder

func (*LinkBuilder) AddQuery

func (b *LinkBuilder) AddQuery(key string, value string) *LinkBuilder

func (*LinkBuilder) AllowedMethod

func (b *LinkBuilder) AllowedMethod(allowedMethod string) *LinkBuilder

func (*LinkBuilder) Build

func (b *LinkBuilder) Build(ctx app.Context) Link

func (*LinkBuilder) ExternalURL

func (b *LinkBuilder) ExternalURL(fullExternalURL string) *LinkBuilder

Use this if you need the link to point to a resource that does not exist on this server. Otherwise, the server's host will be used when building the links

func (*LinkBuilder) Meta

func (b *LinkBuilder) Meta(meta LinkMeta) *LinkBuilder

func (*LinkBuilder) Path

func (b *LinkBuilder) Path(path string) *LinkBuilder

func (*LinkBuilder) Title

func (b *LinkBuilder) Title(title string) *LinkBuilder

func (*LinkBuilder) UseParams

func (b *LinkBuilder) UseParams(params app.Params) *LinkBuilder

type LinkMeta

type LinkMeta struct {
	AllowedMethods []string `json:"allowedMethods,omitempty"`
}

type NotFoundError

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

func NewNotFoundError

func NewNotFoundError(msg string) NotFoundError

func (NotFoundError) Error

func (e NotFoundError) Error() string

type Relationship

type Relationship struct {
	Links ResourceLinks        `json:"links"`
	Data  []ResourceIdentifier `json:"data,omitempty"`
}

https://jsonapi.org/format/#document-resource-object-relationships

type RelationshipBuilder

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

func NewRelationshipBuilder

func NewRelationshipBuilder() *RelationshipBuilder

func (*RelationshipBuilder) AllowOnUninitialized

func (b *RelationshipBuilder) AllowOnUninitialized() *RelationshipBuilder

func (*RelationshipBuilder) Build

func (*RelationshipBuilder) CheckState

func (b *RelationshipBuilder) CheckState(checkStateFn func() bool) *RelationshipBuilder

func (*RelationshipBuilder) Data

func (*RelationshipBuilder) IsAuthenticated

func (b *RelationshipBuilder) IsAuthenticated() *RelationshipBuilder

func (*RelationshipBuilder) OnlyUnauthenticated

func (b *RelationshipBuilder) OnlyUnauthenticated() *RelationshipBuilder

func (*RelationshipBuilder) Related

func (b *RelationshipBuilder) Related(link Link) *RelationshipBuilder

func (*RelationshipBuilder) Roles

func (b *RelationshipBuilder) Roles(roles []string) *RelationshipBuilder

type Resource

type Resource[T any, R any] struct {
	ResourceIdentifier
	Attributes    T             `json:"attributes"`
	Links         ResourceLinks `json:"links"`
	Relationships R             `json:"relationships"`
}

https://jsonapi.org/format/#document-resource-object-relationships

type ResourceBuilder

type ResourceBuilder[T any, R any] struct {
	// contains filtered or unexported fields
}

func NewResourceBuilder

func NewResourceBuilder[T any, R any]() *ResourceBuilder[T, R]

func (*ResourceBuilder[T, R]) Attributes

func (b *ResourceBuilder[T, R]) Attributes(attributes T) *ResourceBuilder[T, R]

func (*ResourceBuilder[T, R]) Build

func (b *ResourceBuilder[T, R]) Build() Resource[T, R]

func (*ResourceBuilder[T, R]) ID

func (b *ResourceBuilder[T, R]) ID(id string) *ResourceBuilder[T, R]

func (*ResourceBuilder[T, R]) Relationships

func (b *ResourceBuilder[T, R]) Relationships(relationships R) *ResourceBuilder[T, R]
func (b *ResourceBuilder[T, R]) SelfLink(link Link) *ResourceBuilder[T, R]

func (*ResourceBuilder[T, R]) Type

func (b *ResourceBuilder[T, R]) Type(resourceType string) *ResourceBuilder[T, R]

type ResourceIdentifier

type ResourceIdentifier struct {
	ID   string `json:"id"`
	Type string `json:"type"`
}
type ResourceLinks struct {
	Self    *Link `json:"self,omitempty"`
	Related *Link `json:"related,omitempty"`
}

type Response

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

func Empty

func Empty() Response

func New

func New[T any, R any](
	ctx app.Context,
	data []Resource[T, R],
	moreRecords bool,
) Response

func (Response) AddHeader

func (r Response) AddHeader(key, value string) Response

func (Response) Collection

func (r Response) Collection() Collection

func (Response) Headers

func (r Response) Headers() map[string]string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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