middlewares

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORSMiddleware

func CORSMiddleware(next http.Handler) http.Handler

CORSMiddleware function sets the headers for the response and returns directly if there is an OPTIONS request

func InitDefaultLogger

func InitDefaultLogger()

InitDefaultLogger sets the default logger to "github.com/gyozatech/noodlog" is no other logger has been set

func RecoverPanicMiddleware

func RecoverPanicMiddleware(h http.Handler) http.Handler

func RequestLoggerMiddleware

func RequestLoggerMiddleware(next http.Handler) http.Handler

RequestLoggerMiddleware is the middleware layer to log all the HTTP requests

func SetLogger

func SetLogger(l interface{})

SetLogger sets the logger for the middlewares

Types

type ReqRespLogStruct

type ReqRespLogStruct struct {
	Request  RequestStruct
	ExecTime time.Duration
	Response ResponseStruct
}

ReqRespLogStruct struct represents the schema for the HTTP Request/ExecutionTime/Response log

type RequestStruct

type RequestStruct struct {
	Verb     string            `json:"verb,omitempty"`
	Path     string            `json:"path,omitempty"`
	Protocol string            `json:"protocol,omitempty"`
	Headers  map[string]string `json:"headers,omitempty"`
	Body     interface{}       `json:"body,omitempty"`
}

RequestStruct struct represents the schema for the HTTP Request log

func HTTPRequest

func HTTPRequest(r *http.Request) RequestStruct

HTTPRequest static function flatten pointers of HTTP Request and obscurate passwords to prepare for logging

type ResponseStruct

type ResponseStruct struct {
	Status  int               `json:"status,omitempty"`
	Headers map[string]string `json:"headers,omitempty"`
	Body    interface{}       `json:"body,omitempty"`
}

ResponseStruct struct represents the schema for the HTTP Response log

func HTTPResponse

func HTTPResponse(statusCode int, responseHeaders http.Header, requestURI string, responseBody string) ResponseStruct

HTTPResponse static function flatten pointers of HTTP Response and obscurate passwords to prepare for logging

type ResponseWriterWrapper

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

ResponseWriterWrapper struct is used to log the response

func NewResponseWriterWrapper

func NewResponseWriterWrapper(w *http.ResponseWriter, r *http.Request) ResponseWriterWrapper

NewResponseWriterWrapper static function creates a wrapper for the http.ResponseWriter

func (ResponseWriterWrapper) Header

func (rww ResponseWriterWrapper) Header() http.Header

Header function overwrites the http.ResponseWriter Header() function

func (ResponseWriterWrapper) Write

func (rww ResponseWriterWrapper) Write(buf []byte) (int, error)

func (ResponseWriterWrapper) WriteHeader

func (rww ResponseWriterWrapper) WriteHeader(statusCode int)

WriteHeader function overwrites the http.ResponseWriter WriteHeader() function

Jump to

Keyboard shortcuts

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