middleware

package module
v0.0.0-...-8c93bd2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 27 Imported by: 5

README

middleware

The repository provides a convenient mechanism for filtering HTTP requests.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes

func Bytes(val string) ([]byte, error)

Bytes converts the given string representation of a byte sequence into a slice of bytes A bytes sequence is encoded in URL-safe base64 without padding

func GetRequestURL

func GetRequestURL(r *http.Request) *url.URL

GetRequestURL returns the request URL

func PopulateFieldFromPath

func PopulateFieldFromPath(msg proto.Message, fieldPathString string, value string) error

PopulateFieldFromPath sets a value in a nested Protobuf structure.

func URLMessageType

func URLMessageType(uri *url.URL) (protoreflect.MessageType, error)

func WithCors

func WithCors(config ...CorsConfig) func(http.Handler) http.Handler

WithCors creates a new Cors handler with passed options.

func WithLogger

func WithLogger() func(http.Handler) http.Handler

WithLogger set up the http logger.

func WithRedirector

func WithRedirector() func(http.Handler) http.Handler

WithRedirector represents an method redirctor

func WithTracer

func WithTracer() func(http.Handler) http.Handler

WithTracer represents an operation telemetry

func WithTransformer

func WithTransformer() func(http.Handler) http.Handler

WithTransformer transforms the input.

Types

type CorsConfig

type CorsConfig struct {
	// AllowedOrigins is a list of origins a cross-domain request can be executed from.
	// If the special "*" value is present in the list, all origins will be allowed.
	// An origin may contain a wildcard (*) to replace 0 or more characters
	// (i.e.: http://*.domain.com). Usage of wildcards implies a small performance penalty.
	// Only one wildcard can be used per origin.
	// Default value is ["*"]
	AllowedOrigins []string
	// AllowedMethods is a list of methods the client is allowed to use with cross-domain requests. Default value is simple methods (HEAD, GET and POST).
	AllowedMethods []string
	// AllowedHeaders is list of non simple headers the client is allowed to use with
	// cross-domain requests.
	// If the special "*" value is present in the list, all headers will be allowed.
	// Default value is [] but "Origin" is always appended to the list.
	AllowedHeaders []string
	// ExposedHeaders indicates which headers are safe to expose to the API of a CORS API specification
	ExposedHeaders []string
}

CorsConfig represents the CORS options.

type FormDecoder

type FormDecoder struct {
	// contains filtered or unexported fields
}

FormDecoder decodes URL values into a proto message.

func NewFormDecoder

func NewFormDecoder() *FormDecoder

NewFormDecoder returns a new decoder.

func (*FormDecoder) Decode

func (d *FormDecoder) Decode(msg proto.Message, values url.Values) error

Parse populates "values" into "msg". A value is ignored if its key starts with one of the elements in "filter".

type ResponseWriter

type ResponseWriter struct {
	ResponseWriter http.ResponseWriter
	ResponseBody   io.ReadWriter
	StatusCode     int32
	ContentLength  int64
}

ResponseWriter repersents a response writer.

func (*ResponseWriter) Flush

func (r *ResponseWriter) Flush()

Flush implements http.Flusher.

func (*ResponseWriter) GetContentLength

func (r *ResponseWriter) GetContentLength() int64

GetContentLength returns the ContentLength.

func (*ResponseWriter) GetStatusCode

func (r *ResponseWriter) GetStatusCode() int32

GetStatusCode returns the StatusCode.

func (*ResponseWriter) Header

func (r *ResponseWriter) Header() http.Header

Header implements http.ResponseWriter

func (*ResponseWriter) Write

func (r *ResponseWriter) Write(data []byte) (int, error)

Write implements http.ResponseWriter

func (*ResponseWriter) WriteHeader

func (r *ResponseWriter) WriteHeader(code int)

WriteHeader implements http.ResponseWriter

Jump to

Keyboard shortcuts

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