Documentation ¶
Index ¶
- Constants
- Variables
- func BadRequest(w http.ResponseWriter, message string)
- func Error(w http.ResponseWriter, err error)
- func Forbidden(w http.ResponseWriter, message string)
- func InternalServerError(w http.ResponseWriter, err error)
- func NotFound(w http.ResponseWriter, message string)
- func OK(w http.ResponseWriter, data any)
- func Raw(w http.ResponseWriter, status int, data any, headers map[string]string)
- func SearchNameFunc[T any](search string, getname func(T) string) func(T) bool
- func SortByFunc[T any](by string, getname func(T) string, gettime func(T) time.Time) func(a, b T) int
- func Unauthorized(w http.ResponseWriter, message string)
- type Page
- func PageFrom[T any](list []T, page, size int, pickfun func(item T) bool, sortfun func(a, b T) int) Page[T]
- func PageFromListOptions[T any](list []T, opts request.ListOptions, namefunc func(item T) string, ...) Page[T]
- func PageFromRequest[T any](req *http.Request, list []T, namefunc func(item T) string, ...) Page[T]
- func PageObjectFromListOptions[T any](list []T, opts request.ListOptions) Page[T]
- func PageObjectFromRequest[T any](req *http.Request, list []T) Page[T]
- type Response
- type StatusError
Constants ¶
View Source
const DefaultPageSize = 10
Variables ¶
View Source
var ServerError = InternalServerError
Functions ¶
func BadRequest ¶
func BadRequest(w http.ResponseWriter, message string)
func Error ¶
func Error(w http.ResponseWriter, err error)
func Forbidden ¶
func Forbidden(w http.ResponseWriter, message string)
func InternalServerError ¶
func InternalServerError(w http.ResponseWriter, err error)
func NotFound ¶
func NotFound(w http.ResponseWriter, message string)
func OK ¶
func OK(w http.ResponseWriter, data any)
func SearchNameFunc ¶
func SortByFunc ¶
func Unauthorized ¶
func Unauthorized(w http.ResponseWriter, message string)
Types ¶
type Page ¶
type Page[T any] struct { Total int64 `json:"total"` List []T `json:"list"` Page int64 `json:"page"` Size int64 `json:"size"` }
func PageFromListOptions ¶
func PageFromRequest ¶
func PageFromRequest[T any](req *http.Request, list []T, namefunc func(item T) string, timefunc func(item T) time.Time) Page[T]
PageFromRequest auto pagination from user request on item name or time in list
func PageObjectFromListOptions ¶
func PageObjectFromListOptions[T any](list []T, opts request.ListOptions) Page[T]
PageObjectFromListOptions used for client.Object pagination T in list use any of T to suit for both eg. Pod(not implement metav1.Object) and *Pod(metav1.Object)
type StatusError ¶
type StatusError struct { Status int `json:"status"` Message string `json:"message"` RawErr error `json:"error,omitempty"` }
func NewStatusError ¶
func NewStatusError(status int, err error) *StatusError
func NewStatusErrorMessage ¶
func NewStatusErrorMessage(status int, message string) *StatusError
func NewStatusErrorf ¶
func NewStatusErrorf(status int, format string, args ...any) *StatusError
NewStatusErrorf acts like fmt.Errorf but returns a StatusError. Usage:
if err:=someprocess(username); err!=nil { return NewStatusErrorf(http.StatusNotFound, "user %s not found: %w", username, err) }
func (StatusError) Error ¶
func (e StatusError) Error() string
Click to show internal directories.
Click to hide internal directories.