xhttputil

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeepCopyRequest

func DeepCopyRequest(r *http.Request) *http.Request

func LoadInput

func LoadInput[T any](ctx context.Context) *T

Utility to load input from request context. for example:

func SomeHandler(w http.ResponseWriter, r *http.Request) {
	ctx	:= r.Context()
	// Output: *dto.AuthLoginReqDTO
	input := httputil.LoadInput[dto.AuthLoginReqDTO](ctx)
}

func WithInput

func WithInput[T any](opts ...InputOptionFn) func(http.Handler) http.Handler

Middleware to parse request input: path variables, headers, query params, body (json and xml) and forms. for example:

router.Use(httputil.WithInput[dto.AuthLoginReqDTO]())

Types

type InputOption

type InputOption interface {

	// Otel span operation name
	WithOperationName(n string) InputOptionFn

	/*
		Understanding Max Memory Allocation, i.e:
			- 1 kilobyte (KB) = 1024 bytes;
			- 1 megabyte (MB) = 1024 kilobytes;
			- 1 MB = 1024 * 1024 = 1,048,576 bytes;
			- 1 MB = 1 * 1024 * 1024;
			- formula for: X MB = X * 1024 * 1024;
	*/
	WithMaxMemory(n int64) InputOptionFn
	WithNestedDirectivesEnabled(enabled bool) InputOptionFn
}

func NewInputOption

func NewInputOption() InputOption

type InputOptionFn

type InputOptionFn func(i *inputOptionValues)

Jump to

Keyboard shortcuts

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