yaml

package
v0.0.0-...-4b7ddd8 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CRUD

type CRUD[T any] struct{}

CRUD provides generic CRUD operations for a given entity type T. All operations return a render.Render to output the response as a YAML object.

func (*CRUD[T]) Create

func (r *CRUD[T]) Create(_ types.Resource[T], entity *T, options *types.ViewOptions) render.Render

Create handles the creation of a new entity and returns a YAML response.

func (*CRUD[T]) Delete

func (r *CRUD[T]) Delete(_ types.Resource[T], _ string, options *types.ViewOptions) render.Render

Delete handles deleting an entity and returns a YAML response.

func (*CRUD[T]) List

func (r *CRUD[T]) List(_ types.Resource[T], entities *[]T, options *types.ViewOptions) render.Render

List handles listing entities and returns a YAML response.

func (*CRUD[T]) Mime

func (r *CRUD[T]) Mime() string

Mime returns the MIME type for YAML responses.

func (*CRUD[T]) Read

func (r *CRUD[T]) Read(_ types.Resource[T], entity *T, options *types.ViewOptions) render.Render

Read handles reading an entity and returns a YAML response.

func (*CRUD[T]) Update

func (r *CRUD[T]) Update(_ types.Resource[T], _ string, entity *T, options *types.ViewOptions) render.Render

Update handles updating an entity and returns a YAML response.

type Response

type Response[T any] struct {

	// Page is the current page number.
	Page int `yaml:"page"`

	// PageSize is the number of items per page.
	PageSize int `yaml:"page_size"`

	// Total is the total number of items.
	Total int `yaml:"total"`

	// TotalPages is the total number of pages.
	TotalPages int `yaml:"total_pages"`

	// Data holds the items for the current page.
	Data *[]T `yaml:"data"`
}

Response represents a paginated response with generic data type T.

func (*Response[T]) Render

func (r *Response[T]) Render(writer http.ResponseWriter) error

Render writes the Response as YAML to the provided http.ResponseWriter, implements render.Render interface.

func (*Response[T]) WriteContentType

func (r *Response[T]) WriteContentType(writer http.ResponseWriter)

WriteContentType sets the Content-Type header to application/x-yaml with UTF-8 charset, implements render.Render interface.

Jump to

Keyboard shortcuts

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