response

package
v1.23.8 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultPageSize = 10

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(w http.ResponseWriter, message string)

func Error

func Error(w http.ResponseWriter, err error)

func NotFound

func NotFound(w http.ResponseWriter, message string)

func OK

func OK(w http.ResponseWriter, data interface{})

func Raw added in v1.23.8

func Raw(w http.ResponseWriter, status int, data interface{}, headers map[string]string)

func ServerError

func ServerError(w http.ResponseWriter, err error)

Types

type NameTimed added in v1.23.8

type NameTimed interface {
	Timed
	Named
}

type Named

type Named interface {
	GetName() string
}

type Page

type Page[T any] struct {
	Total int64 `json:"total"`
	List  []T   `json:"list"`
	Page  int64 `json:"page"`
	Size  int64 `json:"size"`
}

func PageFrom added in v1.23.8

func PageFrom[T any](list []T, page, size int, pickfun func(item T) bool, sortfun func(a, b T) bool) Page[T]

func PageFromRequest added in v1.23.0

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 PageObjectFromRequest added in v1.23.8

func PageObjectFromRequest[T any](req *http.Request, list []T) Page[T]

PageObjectFromRequest 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)

func PageOnly added in v1.23.8

func PageOnly[T any](list []T, page, size int) Page[T]

type Response

type Response struct {
	Message string      `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
	Error   interface{} `json:"error,omitempty"`
}

type StatusError

type StatusError struct {
	Status  int    `json:"status"`
	Message string `json:"message"`
}

func NewError

func NewError(status int, message string) *StatusError

func (StatusError) Error

func (e StatusError) Error() string

type Timed added in v1.23.8

type Timed interface {
	GetCreationTimestamp() metav1.Time
}

Jump to

Keyboard shortcuts

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