Documentation ¶
Index ¶
- type CRUD
- func (r *CRUD[T]) Create(_ types.Resource[T], entity *T, options *types.ViewOptions) render.Render
- func (r *CRUD[T]) Delete(_ types.Resource[T], _ string, options *types.ViewOptions) render.Render
- func (r *CRUD[T]) List(_ types.Resource[T], entities *[]T, options *types.ViewOptions) render.Render
- func (r *CRUD[T]) Mime() string
- func (r *CRUD[T]) Read(_ types.Resource[T], entity *T, options *types.ViewOptions) render.Render
- func (r *CRUD[T]) Update(_ types.Resource[T], _ string, entity *T, options *types.ViewOptions) render.Render
- type Response
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]) 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.
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.
Click to show internal directories.
Click to hide internal directories.