api

package
v2.4.1-0...-6c2315b Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = &ErrorResponse{Code: 404, Status: "Resource not found."}

Functions

func Bind

func Bind(r *http.Request, dest any) error

func Handler

func Handler(h HandlerFunc) http.HandlerFunc

func Render

func Render(w http.ResponseWriter, r *http.Request, response any) error

Render negotiates the content type and renders the response, defaulting to JSON. Response must implement fmt.Stringer to be rendered as plain text.

Types

type Binder

type Binder interface {
	Bind(value string) error
}

type ErrorResponse

type ErrorResponse struct {
	Err  error `json:"-"` // low-level runtime error
	Code int   `json:"-"` // http response status code

	Status  string `json:"status"`          // user-level status message
	Message string `json:"error,omitempty"` // application-level error message, for debugging
}

func BadRequestError

func BadRequestError(err error) *ErrorResponse

func Error

func Error(err error) *ErrorResponse

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

func (*ErrorResponse) Render

type HandlerFunc

type HandlerFunc func(http.ResponseWriter, *http.Request) error

type Hex

type Hex []byte

func (*Hex) Bind

func (h *Hex) Bind(value string) error

func (Hex) MarshalJSON

func (h Hex) MarshalJSON() ([]byte, error)

func (*Hex) UnmarshalJSON

func (h *Hex) UnmarshalJSON(data []byte) error

type HexSlice

type HexSlice []Hex

func (*HexSlice) Bind

func (hs *HexSlice) Bind(value string) error

type Pagination

type Pagination interface {
	Page() uint64
	PerPage() uint64
	// SliceBounds returns safe [start,end) bounds for slicing a collection with the given total length.
	SliceBounds(total uint64) (start, end uint64)
}

Pagination is the resolved (non-optional) pagination configuration. It is only constructible outside this package via PaginationRequest.ToPagination.

type PaginationOptions

type PaginationOptions struct {
	DefaultPerPage uint64
	MaxPerPage     uint64
}

type PaginationRequest

type PaginationRequest struct {
	Set bool `json:"-"`

	Page    *uint64 `json:"page,omitempty"`
	PerPage *uint64 `json:"per_page,omitempty"`
}

func (*PaginationRequest) Bind

func (p *PaginationRequest) Bind(value string) error

func (PaginationRequest) ToPagination

func (p PaginationRequest) ToPagination(opts PaginationOptions) (Pagination, error)

func (*PaginationRequest) UnmarshalJSON

func (p *PaginationRequest) UnmarshalJSON(data []byte) error

type PaginationResponse

type PaginationResponse struct {
	Page       uint64 `json:"page"`
	PerPage    uint64 `json:"per_page"`
	Total      uint64 `json:"total"`
	TotalPages uint64 `json:"total_pages"`
}

func PaginationResponseFromPagination

func PaginationResponseFromPagination(p Pagination, total uint64) PaginationResponse

type Role

type Role spectypes.BeaconRole

func (*Role) Bind

func (r *Role) Bind(value string) error

func (Role) MarshalJSON

func (r Role) MarshalJSON() ([]byte, error)

func (*Role) UnmarshalJSON

func (r *Role) UnmarshalJSON(data []byte) error

type RoleSlice

type RoleSlice []Role

func (*RoleSlice) Bind

func (rs *RoleSlice) Bind(value string) error

type Uint64Slice

type Uint64Slice []uint64

func (*Uint64Slice) Bind

func (us *Uint64Slice) Bind(value string) error

Directories

Path Synopsis
handlers

Jump to

Keyboard shortcuts

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