httprequest

package
v1.7.11 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 20 Imported by: 8 modules, 18 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	FormDataMaxMemory = 256 << 20 // 256 MB
)

Variables

This section is empty.

Functions

func Indent

func Indent(r *http.Request) int

func NewPathItem added in v1.6.19

func NewPathItem(summary, description string, tags ...string) *pathitem

NewPathItem creates a new path item with the given summary, description and tags.

func Query

func Query(q url.Values, v any) error

Read the request query parameters into a structure

func Read

func Read(r *http.Request, v interface{}) error

Read the request body into a structure

Types

type PathItem added in v1.6.19

type PathItem interface {
	// Add one or more tags to the path item.
	// Tags are used to group operations in the OpenAPI document.
	Tag(...string) PathItem

	// Get registers a GET handler with the given summary and operation options.
	Get(handler http.HandlerFunc, fn func(PathOperation)) PathItem

	// Put registers a PUT handler with the given summary and operation options.
	Put(handler http.HandlerFunc, fn func(PathOperation)) PathItem

	// Post registers a POST handler with the given summary and operation options.
	Post(handler http.HandlerFunc, fn func(PathOperation)) PathItem

	// Delete registers a DELETE handler with the given summary and operation options.
	Delete(handler http.HandlerFunc, fn func(PathOperation)) PathItem

	// Patch registers a PATCH handler with the given summary and operation options.
	Patch(handler http.HandlerFunc, fn func(PathOperation)) PathItem

	// Options registers an OPTIONS handler with the given summary and operation options.
	Options(handler http.HandlerFunc, fn func(PathOperation)) PathItem

	// Head registers a HEAD handler with the given summary and operation options.
	Head(handler http.HandlerFunc, fn func(PathOperation)) PathItem

	// Trace registers a TRACE handler with the given summary and operation options.
	Trace(handler http.HandlerFunc, fn func(PathOperation)) PathItem

	// Handler returns the http.HandlerFunc that handles the PathItem
	Handler() http.HandlerFunc

	// Spec returns the openapi.PathItem for a path with optional path parameters
	Spec(string, *jsonschema.Schema) *openapi.PathItem

	// WrapHandler wraps the handler for a specific HTTP method with middleware.
	// The method should be an uppercase HTTP method name (GET, POST, etc.).
	// If no handler is registered for the method, the call is a no-op.
	WrapHandler(method string, fn func(http.HandlerFunc) http.HandlerFunc)
}

type PathOperation added in v1.7.0

type PathOperation interface {
	// Add one or more tags to the operation.
	Tags(...string) PathOperation

	// Set the summary for the operation.
	Summary(string) PathOperation

	// Set the description for the operation.
	Description(string) PathOperation

	// Set the query parameters for the operation from a JSON schema.
	Query(*jsonschema.Schema) PathOperation

	// Mark the operation as deprecated.
	Deprecated() PathOperation

	// Add a request body for the operation with the given content type and schema.
	// An optional description can be provided. If no content type is provided, "application/json" is used.
	RequestBody(schema *jsonschema.Schema, contentType ...string) PathOperation

	// Add a JSON response for the operation with the given status code and schema.
	// An optional description can be provided; if not, the default HTTP status text will be used.
	// A response with another content type for the same status code is kept, so a status code
	// can have more than one content type.
	JSONResponse(status int, schema *jsonschema.Schema, description ...string) PathOperation

	// Add a text/event-stream response for the operation with the given status code, for a
	// stream of server-sent events. An optional description can be provided; if not, the
	// default HTTP status text will be used. A response with another content type for the
	// same status code is kept.
	TextStreamResponse(status int, description ...string) PathOperation

	// Add an error response for the operation with the given status code.
	// An optional description can be provided; if not, the default HTTP status text will be used.
	ErrorResponse(status int, description ...string) PathOperation

	// Add a 204 No Content response, without content, for the operation. An optional
	// description can be provided; if not, the default HTTP status text will be used.
	EmptyResponse(description ...string) PathOperation

	// Return a response for the operation with the given status code and content type.
	// An optional description can be provided; if not, the default HTTP status text will be used.
	// A response with another content type for the same status code is kept.
	Response(status int, contentType string, description ...string) PathOperation

	// Require the named security scheme, with optional scopes, for the operation.
	// The scheme must be registered with the router before the path is registered.
	// Calling Security more than once requires all of the named schemes, which
	// the router enforces by applying each scheme's middleware in turn.
	Security(scheme string, scopes ...string) PathOperation
}

Jump to

Keyboard shortcuts

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