go_http

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: MIT Imports: 4 Imported by: 0

README

go-http

Thin wrapper around http.ServeMux with middlewares.

Go version CI Go Report Card

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CORSOption

type CORSOption struct {
	AllowedMethods []string
	AllowedOrigins []string
}

type LoggingOption

type LoggingOption struct {
	ExcludedPrefixes []string
}

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware is a function type that represents an HTTP middleware.

type MiddlewareOption

type MiddlewareOption func(*middlewareOptions)

func WithCORS

func WithCORS(allowedMethods, allowedOrigins []string) MiddlewareOption

WithCORS returns a MiddlewareOption that sets the CORS middleware options.

func WithLogging

func WithLogging(prefixes []string) MiddlewareOption

WithLogging returns a MiddlewareOption that sets the Logging middleware options.

func WithTelemetry

func WithTelemetry(excludedPrefixes []string) MiddlewareOption

WithTelemetry returns a MiddlewareOption that sets the Telemetry (Metrics & Traces) middleware options.

type Router

type Router struct {
	*http.ServeMux
	// contains filtered or unexported fields
}

Router is a custom HTTP router that supports middlewares.

func NewRouter

func NewRouter(opts ...MiddlewareOption) *Router

NewRouter creates a new Router with the specified MiddlewareOptions. It sets up middlewares for CORS, logging, and tracing based on the provided options.

func (*Router) HandlerFunc

func (r *Router) HandlerFunc() *http.HandlerFunc

HandlerFunc method returns a http.HandlerFunc that wraps the Router with the configured middlewares.

type TelemetryOption

type TelemetryOption struct {
	ExcludedPrefixes []string
}

Directories

Path Synopsis
middlewares

Jump to

Keyboard shortcuts

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