http

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2025 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidContentType = errors.New("invalid content type")
	ErrEmptyBody          = errors.New("empty body")
)

Functions

func NewTool

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

Types

type Client

type Client interface {
	Blackbox
	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
	DecodeBody(r *http.Request, v any) error
}

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