http

package
v2.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderAllowHeaders    = "Access-Control-Allow-Headers"
	HeaderAllowMethods    = "Access-Control-Allow-Methods"
	HeaderAllowOrigin     = "Access-Control-Allow-Origin"
	HeaderExposeHeader    = "Access-Control-Expose-Headers"
	HeaderAccessMaxAge    = "Access-Control-Max-Age"
	HeaderRequestID       = "X-Request-Id"
	HeaderXForwardedFor   = "X-Forwarded-For"
	HeaderXForwardedProto = "X-Forwarded-Proto"
	HeaderAuthorization   = "Authorization"
	HeaderReferer         = "Referer"
	HeaderUserAgent       = "User-Agent"
	HeaderAccept          = "Accept"
	HeaderContentType     = "Content-Type"
)

Headers

Variables

View Source
var (
	ErrNotHTTPRequest  = errors.New("missmatch type, request should be *http.Request")
	ErrNotHTTPResponse = errors.New("mismatch type, response should be *http.Response")
)

Standard HTTP Errors

Functions

func DefaultMetricsNameFormatter added in v2.0.2

func DefaultMetricsNameFormatter(namespace string, r *http.Request) string

func DefaultSpanNameFormatter added in v2.0.2

func DefaultSpanNameFormatter(operation string, r *http.Request) string

func NewHandler

func NewHandler(fn Handler, opts ...HandlerOption) net_http.Handler

NewHandler returns http.Handler

func NewResponse

func NewResponse(req *net_http.Request, opts ...ResponseOption) *net_http.Response

NewResponse returns a new net/http.Response based on incoming request and the available options passed to it

func NoopBefore

func NoopBefore(cx context.Context, _ *http.Request) context.Context

NoopBefore is Before which has no operation

func NoopMiddleware

func NoopMiddleware(next endpoint.Endpoint) endpoint.Endpoint

NoopMiddleware is middleware that does nothing It is returned if a given middleware is not enabled

Types

type AfterFunc

type AfterFunc kit_http.ServerResponseFunc

type BeforeFunc

type BeforeFunc kit_http.RequestFunc

type ChiMuxOption added in v2.0.2

type ChiMuxOption func(*chiMuxer)

go-chi muxer which is default multiplexer for go-base

func MethodNotAllowedChiMuxOption added in v2.0.2

func MethodNotAllowedChiMuxOption(handlerFunc http.HandlerFunc) ChiMuxOption

MethodNotAllowedChiMuxOption sets a custom http.HandlerFunc to handle '405' errors in URL Paths

func NotFoundHandlerChiMuxOption added in v2.0.2

func NotFoundHandlerChiMuxOption(handlerFunc http.HandlerFunc) ChiMuxOption

NotFoundHandlerChiMuxOption sets a custom http.HandlerFunc to handle '404' errors when the URL is incorrect

type ContextKey

type ContextKey int

ContextKey is key for context

const (
	ContextKeyRequestMethod ContextKey = iota
	ContextKeyRequestURI
	ContextKeyRequestPath
	ContextKeyRequestProto
	ContextKeyRequestHost
	ContextKeyRequestRemoteAddr
	ContextKeyRequestXForwardedFor
	ContextKeyRequestXForwardedProto
	ContextKeyRequestAuthorization
	ContextKeyRequestReferer
	ContextKeyRequestUserAgent
	ContextKeyRequestXRequestID
	ContextKeyRequestAccept
	ContextKeyResponseHeaders
	ContextKeyResponseSize
)

ContextKeys

type CorsOptions

type CorsOptions cors.Options

type Decoder

type Decoder func(context.Context, *net_http.Request) (interface{}, error)

Decoder provides method to decode the body of the Request

func NewDefaultDecoder

func NewDefaultDecoder() Decoder

NewDefaultDecoder returns default decoder for http

func NopRequestDecoder

func NopRequestDecoder() Decoder

NopRequestDecoder is no operation Decoder for the request

type Encoder

type Encoder func(context.Context, net_http.ResponseWriter, interface{}) error

Encoder denotes the Encoder used to write the data on stream after reading the interface

func NewDefaultEncoder

func NewDefaultEncoder() Encoder

NewDefaultEncoder returns a default Encoder used by http

func NewDefaultJSONEncoder

func NewDefaultJSONEncoder() Encoder

NewDefaultJSONEncoder encodes the response in JSON

type ErrorEncoder

type ErrorEncoder func(context.Context, error, net_http.ResponseWriter)

ErrorEncoder defines the Encoder that handles error

type ErrorHandler

type ErrorHandler interface {
	transport.ErrorHandler
}

ErrorHandler wraps onn top of transport.ErrorHandler and provides a hook for diagnostic purpose

type Filter

type Filter func(http.Handler) http.Handler

func AllowContentTypeFilter

func AllowContentTypeFilter(contentTypes ...string) Filter

collection of filters to be used with transport or handlers AllowContentTypeFilter enforces a whitelist of request Content-Types otherwise responds with a 415 Unsupported Media Type status.

func CleanPathFilter

func CleanPathFilter() Filter

CleanPath middleware will clean out double slash mistakes from a user's request path. For example, if a user requests /users//1 or //users////1 will both be treated as: /users/1

func CorsFilterWithCustomOptions

func CorsFilterWithCustomOptions(options CorsOptions) Filter

CorsFilterWithCustomOptions is cors filter with custom configurable options

func CorsFilterWithDefaults

func CorsFilterWithDefaults() Filter

CorsFilterWithDefaults is cors filter with sane defaults. It sets the https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS headers for any server response

func CustomMetricsFilter added in v2.0.2

func CustomMetricsFilter(
	namespace string,
	provider metrics.Provider,
	formatter MetricsNameFormatter,
	tagsGenerators ...MetricsTagGenerator,
) Filter

func CustomRequestIDFilter

func CustomRequestIDFilter(formatter RequestIDFormatter, customHeaders ...string) Filter

CustomRequestIDFilter returns a HandlerOption for a customheader to be populated with request id, generated at filter Each Request by default should have `x-request-id` as it has been made default of the Transport as a filter, this is only to set the same value to different headers with a prefix & suffix

func DeleteHeadersFilter

func DeleteHeadersFilter(headers ...string) Filter

DeleteHadersFilter deletes the headers in http request

func GzipCompressionFilter

func GzipCompressionFilter(level int, types ...string) Filter

GZipCompressionFilter is a middleware that compresses response body of a given content types to a data format based on Accept-Encoding request header. It uses a given compression level. NOTE: make sure to set the Content-Type header on your response otherwise this middleware will not compress the response body. For ex, in your handler you should set w.Header().Set("Content-Type", http.DetectContentType(yourBody)) or set it manually. Passing a compression level of 5 is sensible value

func NoopFilter

func NoopFilter() Filter

NoopFilter doesn't do anything

func OpenTelemetryFilter added in v2.0.2

func OpenTelemetryFilter(
	namespace string,
	provider OpenTelemetryProvider,
	tags []KeyValue,
	filters ...OpenTelemetryRequestFilter,
) Filter

OpenTelemetryFilter uses OpenTelemetry to publish events There are multiple providers for OpenTelemetry that can be used A simple example of using this filter is by just setting this up in the filter chain and in the application, set the provider Example using Datadog gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentelemetry

import (
	"go.opentelemetry.io/otel"
	ddotel "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentelemetry"
)

func main() {
	provider := ddotel.NewTracerProvider()
	defer provider.Shutdown()
	otel.SetTracerProvider(provider)
}

func RedirectSlashFilter

func RedirectSlashFilter() Filter

RedirectSlashes is a middleware that will match request paths with a trailing slash and redirect to the same path, less the trailing slash.

NOTE: RedirectSlashes middleware is *incompatible* with http.FileServer, see https://github.com/go-chi/chi/issues/343

func SetRequestHeaderFilter added in v2.0.2

func SetRequestHeaderFilter(key, value string) Filter

SetRequestHeaderFilter sets custom header for downstream to consume, useful if we call other downstreams directly from http layer

func SetResponseHeaderFilter added in v2.0.2

func SetResponseHeaderFilter(key, value string) Filter

SetResponseHeaderFilter is a convenience handler to set a response header key/value

func TraceLoggingFilter

func TraceLoggingFilter(logger log.Logger, fieldGenerators ...TraceLogFieldsGen) Filter

TraceLoggingFilter supersedes `NewTraceLoggerFinalizerHandlerOption` as this is more closer to the end of request handling phase. This reads most of the properties from Context and writes log line for loggers to consume.

func WithChi added in v2.0.2

func WithChi(middleware func(http.Handler) http.Handler) Filter

WithChi allows you to use chi's supported middleware. To see the list of available middlewares, refer https://github.com/go-chi/chi?tab=readme-ov-file#core-middlewares For example, to use middleware.BasicAuth, set it as follows

	transportConfigOptions := append(
		transportConfigOptions,
		[]http.TransportConfigOption{
			http.WithCustomHostPort(cx.String("http.host"), cx.String("http.port")),
			http.WithTraceLogging(),
			http.WithFilters(
				WithChi(middleware.BasicAuth(...)),
			),
		}...,
	),
)

type Handler

type Handler endpoint.Endpoint

Handler is wrapper on top of endpoint.Endpoint

type HandlerFunc

type HandlerFunc func(ctx context.Context, req *net_http.Request) (*net_http.Response, error)

HandlerFunc defines the default wrapper for request/response handling in http transport. By default we can't support the default net_http.handler interface as the `ServeHTTP(r *http.Request, rw http.ResponseWriter)` func has rw built in which overlaps our abstraction This here instead gives us the ability to expose this as endpoint.Endpoint and use it in the go-kit chain

type HandlerOption

type HandlerOption func(*handler)

HandlerOption provides ways to modify the handler

func HandlerWithAfterFunc

func HandlerWithAfterFunc(fn AfterFunc) HandlerOption

HandlerWithAfterFunc returns a request handler with customer after function

func HandlerWithBeforeFunc

func HandlerWithBeforeFunc(fn BeforeFunc) HandlerOption

HandlerWithBeforeFunc returns a request handler with customer before function

func HandlerWithDecoder

func HandlerWithDecoder(fn Decoder) HandlerOption

HandlerWithDecoder returns a request handler with a customer decoer function

func HandlerWithEncoder

func HandlerWithEncoder(fn Encoder) HandlerOption

HandlerWithEncoder returns a request handler with customer encoder function

func HandlerWithEndpointMiddleware

func HandlerWithEndpointMiddleware(fn endpoint.Middleware) HandlerOption

HandlerWithEndpointMiddleware provides an ability to add a middleware of the base type

func HandlerWithErrorEncoder

func HandlerWithErrorEncoder(fn ErrorEncoder) HandlerOption

HandlerWithErrorEncoder returns a request handler with a customer error encoder function

func HandlerWithErrorhandler

func HandlerWithErrorhandler(fn ErrorHandler) HandlerOption

HandlerWithErrorhandler returns a request handler with a custom error handler

func HandlerWithFilter

func HandlerWithFilter(f Filter) HandlerOption

HandlerWithFilter provides an ability to add a

func HandlerWithMiddleware

func HandlerWithMiddleware(fn Middleware) HandlerOption

HandlerWithMiddleware sets middleware for request

func NewDeleteHeaderHandlerOption

func NewDeleteHeaderHandlerOption(headers ...string) HandlerOption

NewDeleteHeaderHandlerOption deletes the headers from net_http.Request before it is sent to HandlerFunc

func NewErrorEncoderHandlerOptions

func NewErrorEncoderHandlerOptions(fn ErrorEncoder) HandlerOption

NewErrorEncoderHandlerOptions provides a handler specific error encoder

func NewFiltersHandlerOption

func NewFiltersHandlerOption(filters ...Filter) HandlerOption

NewFiltersHandlerOption allows custom filter added per route

func NewGoKitDecoderHandlerOption

func NewGoKitDecoderHandlerOption(fn kit_http.DecodeRequestFunc) HandlerOption

NewGoKitDecoderHandlerOption sets a decoder of a type kit_http.DecodeRequestFunc

func NewGoKitEncoderHandlerOption

func NewGoKitEncoderHandlerOption(fn kit_http.EncodeResponseFunc) HandlerOption

NewGoKitEncoderHandlerOption provides option to encode the request

func NewGoKitErrorEncoderHandlerOption

func NewGoKitErrorEncoderHandlerOption(fn kit_http.ErrorEncoder) HandlerOption

NewGoKitErrorEncoderHandlerOption provides an option to set error encoder for handler or transport based on Go-Kit's ErrorEncoder

func NewRequestIDHandlerOption

func NewRequestIDHandlerOption(formatter RequestIDFormatter, customHeaders ...string) HandlerOption

NewRequestIDHandlerOption returns a HandlerOption for a customheader to be populated with request id, generated at filter This is same as CustomRequestIDFilter except at per Handler level

func NewSetRequestHeader

func NewSetRequestHeader(key, val string) HandlerOption

NewSetRequestHeader sets the request header

func NewSetResponseHeader

func NewSetResponseHeader(key, val string) HandlerOption

NewSetResponseHeader sets the response header

type KeyValue

type KeyValue struct {
	Key   string
	Value string
}

keyValues is a simple key value

func (*KeyValue) String added in v2.0.2

func (kv *KeyValue) String() string

func (*KeyValue) Strings added in v2.0.4

func (kv *KeyValue) Strings() []string

type MetricsNameFormatter

type MetricsNameFormatter func(namespace string, r *http.Request) string

type MetricsTagGenerator added in v2.0.2

type MetricsTagGenerator func(rw WrapResponseWriter, req *http.Request) []KeyValue

type Middleware

type Middleware endpoint.Middleware

Middleware defines the middleware for request

type Muxer

type Muxer interface {
	// ServeHTTP
	http.Handler

	// URLParser returns the parsing method used by
	// the multiplexer
	URLParser() URLParser

	// Default Handler Method is all that is needed
	Handler(method, url string, fn http.Handler)

	Use(filters ...Filter)
}

Muxer defines the standard Multiplexer for http Request

func NewGorillaMux

func NewGorillaMux() Muxer

type OpenTelemetryProvider

type OpenTelemetryProvider interface {
	metric.MeterProvider
	trace.TracerProvider
}

type OpenTelemetryRequestFilter added in v2.0.2

type OpenTelemetryRequestFilter otelhttp.Filter

type PanicCallback

type PanicCallback func(*PanicInformation)

PanicCallback gives a callback option to handle Panic with details

type PanicFormatter

type PanicFormatter interface {
	Format(http.ResponseWriter, *http.Request, *PanicInformation)
}

PanicFormatter provides an interface to print stack trace in customized way

type PanicFormatterType

type PanicFormatterType uint
const (
	TextPanicFormatter PanicFormatterType = iota
	HTMLPanicFormatter
)

type PanicInformation

type PanicInformation struct {
	RecoveredPanic interface{}
	Stack          []byte
	Request        *http.Request
}

PanicInformation holds all elements required to print stack information about the panic

func (*PanicInformation) RequestInfo

func (p *PanicInformation) RequestInfo() string

func (*PanicInformation) StackString

func (p *PanicInformation) StackString() string

PanicInformation

type RecoveryOption

type RecoveryOption func(*recovery)

func WithCustomFormatter

func WithCustomFormatter(formatter PanicFormatter) RecoveryOption

func WithFormatterType

func WithFormatterType(formatterType PanicFormatterType) RecoveryOption

func WithHTMLFormatter

func WithHTMLFormatter() RecoveryOption

func WithStack

func WithStack(stackSize int, stackOtherGoroutines bool) RecoveryOption

func WithTextFormatter

func WithTextFormatter() RecoveryOption

func WithoutStack

func WithoutStack() RecoveryOption

type RequestIDFormatter

type RequestIDFormatter func(uuid string) string

type ResponseOption

type ResponseOption func(*net_http.Response)

ResponseOption defines the options which modify the net/http Response

func ResponseWithBytes

func ResponseWithBytes(bt []byte) ResponseOption

ResponseWithBytes provide option to update the response body with Bytes data

func ResponseWithCode

func ResponseWithCode(code int) ResponseOption

ResponseWithCode provides option to update the status code for the reponse

func ResponseWithReader

func ResponseWithReader(reader io.Reader) ResponseOption

ResponseWithReader provies option to update the body of the response with a custom reader

type SpanNameFormatter

type SpanNameFormatter func(operation string, r *http.Request) string

type TraceLogFieldsGen added in v2.0.2

type TraceLogFieldsGen func(rw WrapResponseWriter, req *http.Request) []log.Field

type Transport

type Transport struct {
	*http.Server
	// contains filtered or unexported fields
}

Transport is a wrapper around http.Server with sane defaults dimfeld/httptreemux is used as default multiplexer and Go-Kit's http transport is used as default request handler

func NewHTTPTransport

func NewHTTPTransport(
	name string,
	options ...TransportConfigOption,
) (*Transport, error)

func NewTransport deprecated

func NewTransport(
	host, port string,
	options ...TransportOption,
) (*Transport, error)

NewTransport returns a new transport

Deprecated: use the new config interface to create Transport. This one tries to do the best with sane defaults, but the configuration is way more streamlined in the new intializer `NewHttpTansport`.

func (*Transport) Close

func (tr *Transport) Close() error

Close shuts down Transport

func (*Transport) DELETE

func (tr *Transport) DELETE(
	url string,
	fn Handler,
	options ...HandlerOption,
)

DELETE provides flexible interface for handling request for delete method it exposes a structured logical break up of the function handling the request. breakup consists of - decoder (decodes the request & converts to business object) - endpoint (handles the business object, and returns a result in business object ) - encoder (converts business object into response)

func (*Transport) Delete

func (tr *Transport) Delete(url string, fn HandlerFunc, options ...HandlerOption)

Delete handles DELETE request

func (*Transport) GET

func (tr *Transport) GET(
	uri string,
	fn Handler,
	options ...HandlerOption,
)

GET provides flexible interface for handling request for GET method It exposes a structured logical break up of the function handling the request. Breakup consists of - decoder (decodes the request & converts to business object) - endpoint (handles the business object, and returns a result in business object ) - encoder (converts business object into response)

func (*Transport) Get

func (tr *Transport) Get(url string, fn HandlerFunc, options ...HandlerOption)

Get handles GET request

func (*Transport) HANDLE

func (tr *Transport) HANDLE(met, url string, fn Handler, options ...HandlerOption)

HANDLE gives a generic method agnostic way of binding handler to the request

func (*Transport) HEAD

func (tr *Transport) HEAD(
	url string,
	fn Handler,
	options ...HandlerOption,
)

HEAD provides flexible interface for handling request for head method it exposes a structured logical break up of the function handling the request. breakup consists of - decoder (decodes the request & converts to business object) - endpoint (handles the business object, and returns a result in business object ) - encoder (converts business object into response)

func (*Transport) Handle

func (tr *Transport) Handle(method, url string, fn HandlerFunc, options ...HandlerOption)

Handle is generic method to allow custom bindings of URL with a method and it's handler

func (*Transport) Head

func (tr *Transport) Head(url string, fn HandlerFunc, options ...HandlerOption)

Head handles HEAD request

func (*Transport) Mux

func (tr *Transport) Mux() Muxer

Mux returns the default multiplexer

func (*Transport) OPTION

func (tr *Transport) OPTION(
	url string,
	fn Handler,
	options ...HandlerOption,
)

OPTION provides flexible interface for handling request for option method it exposes a structured logical break up of the function handling the request. breakup consists of - decoder (decodes the request & converts to business object) - endpoint (handles the business object, and returns a result in business object ) - encoder (converts business object into response)

func (*Transport) Open

func (tr *Transport) Open() error

Open starts the Transport

func (*Transport) Options

func (tr *Transport) Options(url string, fn HandlerFunc, options ...HandlerOption)

Options handles OPTIONS request

func (*Transport) PATCH

func (tr *Transport) PATCH(
	url string,
	fn Handler,
	options ...HandlerOption,
)

PATCH provides flexible interface for handling request for patch method it exposes a structured logical break up of the function handling the request. breakup consists of - decoder (decodes the request & converts to business object) - endpoint (handles the business object, and returns a result in business object ) - encoder (converts business object into response)

func (*Transport) POST

func (tr *Transport) POST(
	url string,
	fn Handler,
	options ...HandlerOption,
)

POST provides flexible interface for handling request for post method it exposes a structured logical break up of the function handling the request. breakup consists of - decoder (decodes the request & converts to business object) - endpoint (handles the business object, and returns a result in business object ) - encoder (converts business object into response)

func (*Transport) PUT

func (tr *Transport) PUT(
	url string,
	fn Handler,
	options ...HandlerOption,
)

PUT provides flexible interface for handling request for put method it exposes a structured logical break up of the function handling the request. breakup consists of - decoder (decodes the request & converts to business object) - endpoint (handles the business object, and returns a result in business object ) - encoder (converts business object into response)

func (*Transport) Patch

func (tr *Transport) Patch(url string, fn HandlerFunc, options ...HandlerOption)

Patch handles PATCH request

func (*Transport) Post

func (tr *Transport) Post(url string, fn HandlerFunc, options ...HandlerOption)

Post handles POST request

func (*Transport) Put

func (tr *Transport) Put(url string, fn HandlerFunc, options ...HandlerOption)

Put handles PUT request

func (*Transport) TRACE

func (tr *Transport) TRACE(
	url string,
	fn Handler,
	options ...HandlerOption,
)

TRACE provides flexible interface for handling request for trace method it exposes a structured logical break up of the function handling the request. breakup consists of - decoder (decodes the request & converts to business object) - endpoint (handles the business object, and returns a result in business object ) - encoder (converts business object into response)

func (*Transport) Trace

func (tr *Transport) Trace(url string, fn HandlerFunc, options ...HandlerOption)

Trace handles TRACE request

type TransportConfigOption

type TransportConfigOption func(*config) error

func WithCustomHeadersForRequestID

func WithCustomHeadersForRequestID(formatter RequestIDFormatter, headers ...string) TransportConfigOption

WithCustomHeadersForRequestID lets you configure what all headers should have request ID. It is useful for cases where internal tracking is based on

func WithCustomHostPort

func WithCustomHostPort(host, port string) TransportConfigOption

func WithCustomLogger

func WithCustomLogger(logger log.Logger) TransportConfigOption

WithCustomLogger uses the logger passed as an argument

func WithCustomMetrics

func WithCustomMetrics(
	enabled bool,
	provider metrics.Provider,
	formatter MetricsNameFormatter,
) TransportConfigOption

WithCustomMetrics lets you use `metrics.Counter`, `metrics.Histogram` & `metrics.Gauge` interfaces instead of relying on some third party interfaces. Not passing custom formatter will result in default formatter being used.

func WithCustomPanicFormatter

func WithCustomPanicFormatter(formatter PanicFormatter) TransportConfigOption

func WithCustomTimeouts

func WithCustomTimeouts(idle, read, write time.Duration) TransportConfigOption

func WithDefaultPanicFormatter

func WithDefaultPanicFormatter(panicFormatterType PanicFormatterType) TransportConfigOption

func WithFilters

func WithFilters(filters ...Filter) TransportConfigOption

WithFilters allows to add custom Filter to the Transport

func WithHandlerOptionForTransport added in v2.0.2

func WithHandlerOptionForTransport(options ...HandlerOption) TransportConfigOption

func WithHeartbeats

func WithHeartbeats(heartbeats ...string) TransportConfigOption

WithHeartbeats sets list of path which returns a simple 200 & ping response

func WithLogger

func WithLogger(level string) TransportConfigOption

WithLogger creates a new logger and associates it with Transport

func WithOpenTelemetryMetrics

func WithOpenTelemetryMetrics(
	enabled bool,
	provider OpenTelemetryProvider,
	tags []KeyValue,
	filters ...OpenTelemetryRequestFilter,
) TransportConfigOption

func WithTraceLogging added in v2.0.2

func WithTraceLogging(fieldsGens ...TraceLogFieldsGen) TransportConfigOption

func WithTransportOption added in v2.0.2

func WithTransportOption(options ...TransportOption) TransportConfigOption

WithTransportOption can be used to set other overridable Transport Options

func WithVersion

func WithVersion(version string) TransportConfigOption

type TransportOption

type TransportOption func(*Transport)

TransportOption sets options parameters to Transport

func WithErrorEncoder

func WithErrorEncoder(fn ErrorEncoder) TransportOption

WithErrorEncoder sets error handler for the error generated by the request

func WithFullDefaults deprecated

func WithFullDefaults() TransportOption

WithFullDefaults sets default ServerOption, used by every request handler It sets following filters for the request

  • RequestID
  • CORS
  • DefaultErrorHandler
  • DefaultTranceLogger (using transport.Logger)

Deprecated: use `WithProductionDefaults` for Production Environments, `WithDevDefaults` for Dev Env

func WithHandlerOption

func WithHandlerOption(options ...HandlerOption) TransportOption

WithHandlerOption overrides the default HandlerOption for the transport

func WithMuxer

func WithMuxer(mux Muxer) TransportOption

WithMuxer sets the multiplexer for transport

func WithTimeout

func WithTimeout(idle, write, read time.Duration) TransportOption

WithTimeout sets the custom net_http.Server timeout for the Transport

func WithTransportErrorEncoder

func WithTransportErrorEncoder(fn ErrorEncoder) TransportOption

WithTransportErrorEncoder lets us put a custom error encoder for the Transport applicable at Transport level. There is a provision to do this per handler using NewErrorEncoder, however if a handler doesn't have an error encoder this will be used as default If any Handler doesn't have an error encoder defined when throwing an error this error encoder is used Deprecated: default error handler is not overridable, defaultErrorHandler will become default in next release

type URLParams

type URLParams map[string]string

func (URLParams) ByName

func (up URLParams) ByName(key string) (value string)

func (URLParams) Param

func (up URLParams) Param(key string) (value string, found bool)

type URLParamsParser deprecated

type URLParamsParser interface {
	ByName(string) string
}

Deprecated: use URLParser instead of URLParamsParser

func Parameters

func Parameters(r *http.Request) URLParamsParser

Parameters returns the request parameters extracted from http.Request. This method will only work with DefaultMux used in go-base This method here is only for backwards compatibility. Don't use this method Deprecated: in favour of parser := transport.Mux().URLParser(); parser.Parse(r).Get("key")

type URLParser

type URLParser interface {
	Parse(r *http.Request) URLParams
}

type WrapResponseWriter

type WrapResponseWriter interface {
	http.ResponseWriter
	// Status returns the HTTP status of the request, or 0 if one has not
	// yet been sent.
	Status() int
	// BytesWritten returns the total number of bytes sent to the client.
	BytesWritten() int
	// Tee causes the response body to be written to the given io.Writer in
	// addition to proxying the writes through. Only one io.Writer can be
	// tee'd to at once: setting a second one will overwrite the first.
	// Writes will be sent to the proxy before being written to this
	// io.Writer. It is illegal for the tee'd writer to be modified
	// concurrently with writes.
	Tee(io.Writer)
	// Unwrap returns the original proxied target.
	Unwrap() http.ResponseWriter
}

WrapResponseWriter is a proxy around an http.ResponseWriter that allows you to hook into various parts of the response process.

func NewWrapResponseWriter

func NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWriter

NewWrapResponseWriter wraps an http.ResponseWriter, returning a proxy that allows you to hook into various parts of the response process.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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