http

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTool

func NewTool(c Client, opts contract.ToolOptions[Client]) *defaultTool

Types

type Blackbox

type Blackbox interface {
	contract.HTTPRequester
	contract.HTTPWriter
}

WARN: Methods from this interface require black-box testing because they internally call package-level functions (e.g., http.NewRequest) that are not easily mockable or stubbable. While we have access to their implementation, mocking or stubbing these functions is not practical. As a result, these methods are best tested using black-box testing techniques, such as input-based testing, where explicit error scenarios are triggered. Alternatively, these methods can also be tested using function variables.

type Client

type Client interface {
	Blackbox
	contract.HTTPDoer
	contract.HTTPWriter
	QueryString(pairs ...string) string
	RespondJSON(w http.ResponseWriter, v any, status int, escapeHTML bool) error
	RespondError(w http.ResponseWriter, status int, escapeHTML bool)
	RespondGzipJSON(w http.ResponseWriter, v any, status int, escapeHTML bool) error
	RespondGzipError(w http.ResponseWriter, status int, escapeHTML bool)
	ValidateQueryParams(q map[string][]string, rules ...*QueryParamRule) error
	ServeHTML(w http.ResponseWriter, body io.Reader, status int)
	CopyHeaders(dst, src *http.Request, headers ...string)
	GetHeaders(r *http.Request) http.Header
}

type QueryParamRule

type QueryParamRule struct {
	Key                   string   // Name of the query parameter.
	DefaultValue          string   // Default value if not provided in the request.
	AcceptedValues        []string // Accepted values; nil allows any value.
	MultipleValuesAllowed bool     // Whether multiple values are permitted.
	Optional              bool     // Whether the parameter is optional.
}

QueryParamRule defines validation rules for a query parameter. It specifies constraints such as key, default value, allowed values, and multiplicity.

Jump to

Keyboard shortcuts

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