webapitestutil

package module
v0.0.0-...-ccb06fb Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

README

Package cloudeng.io/webapi/webapitestutil

import cloudeng.io/webapi/webapitestutil

Functions

Func NewEchoHandler
func NewEchoHandler(value any) http.Handler

NewEchoHandler returns an http.Handler that echos the json encoded value of the supplied value.

Func NewHeaderEchoHandler
func NewHeaderEchoHandler() http.Handler

NewHeaderEchoHandler returns an http.Handler that returns the json encoded value of the request headers as its response body.

Func NewRetryHandler
func NewRetryHandler(retries int) http.Handler

NewRetryHandler returns an http.Handler that returns an http.StatusTooManyRequests until retries in reached in which case it returns an http.StatusOK with a body containing the json encoded value of retries.

Func NewServer
func NewServer(handler http.Handler) *httptest.Server

NewServer creates a new httptest.Server using the supplied handler.

Types

Type Paginated
type Paginated struct {
	Payload int
	Current int
	Last    int
}

Paginated is an example return type for a paginated API.

Type PaginatedHandler
type PaginatedHandler struct {
	Last int
	// contains filtered or unexported fields
}

PaginatedHandler is an example http.Handler that returns a Paginated response, that is accepts a parameter called 'current' which is the page to returned. Last should be initialized the number of available pages.

Methods
func (ph *PaginatedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEchoHandler

func NewEchoHandler(value any) http.Handler

NewEchoHandler returns an http.Handler that echos the json encoded value of the supplied value.

func NewHeaderEchoHandler

func NewHeaderEchoHandler() http.Handler

NewHeaderEchoHandler returns an http.Handler that returns the json encoded value of the request headers as its response body.

func NewRetryHandler

func NewRetryHandler(retries int) http.Handler

NewRetryHandler returns an http.Handler that returns an http.StatusTooManyRequests until retries in reached in which case it returns an http.StatusOK with a body containing the json encoded value of retries.

func NewServer

func NewServer(handler http.Handler) *httptest.Server

NewServer creates a new httptest.Server using the supplied handler.

Types

type Paginated

type Paginated struct {
	Payload int
	Current int
	Last    int
}

Paginated is an example return type for a paginated API.

type PaginatedHandler

type PaginatedHandler struct {
	Last int
	// contains filtered or unexported fields
}

PaginatedHandler is an example http.Handler that returns a Paginated response, that is accepts a parameter called 'current' which is the page to returned. Last should be initialized the number of available pages.

func (*PaginatedHandler) ServeHTTP

func (ph *PaginatedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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