middleware

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2020 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const RequestIdHttpHeader = "X-Request-ID"
View Source
const RequestIdKey requestIdCxtKey = 0

RequestIdKey is the key to store an unique request ID in a request context.

Variables

This section is empty.

Functions

func ClearFieldByName

func ClearFieldByName(obj interface{}, fieldName string) error

ClearFieldByName clears all fields and nested fields in an object that have a specified name.

func ClearFieldByType

func ClearFieldByType(obj interface{}, t reflect.Type) error

ClearFieldByType clears all fields and nested fields in an object that have a specified type.

func GetRequestID

func GetRequestID(ctx context.Context) string

GetRequestID returns a request ID for the given context; otherwise an empty string will be returned if the context is nil or the request ID can not be found.

func Log

func Log(log LogFunc) xserver.Middleware

Log creates a middleware to log HTTP requests and responses.

func LogHandler

func LogHandler(log LogFunc) routing.Handler

LogHandler creates a middleware handler for logging HTTP requests and responses

func RequestID

func RequestID() xserver.Middleware

RequestID creates a middleware which creates a request ID and store the ID in the request context.

Types

type LogEntry

type LogEntry struct {
	Request   *logRequest  `json:",omitempty"`
	Response  *logResponse `json:",omitempty"`
	Duration  float64      `json:"durationMs"`
	Timestamp string
}

type LogFunc

type LogFunc func(r *http.Request, w *LogResponseWriter, elapsed time.Duration)

LogFunc represents the func header for logging HTTP requests and responses on a middleware.

func NewLogger

func NewLogger(timeFormat string, pathsToIgnore []string, logFunc func(entity LogEntry, values ...interface{})) LogFunc

NewLogger returns a new Logger based on APIKit middleware.LogFunc by recognizing the given time format.

func NewMaskingLogger

func NewMaskingLogger(timeFormat string, fieldsToMask []string, typesToMask []reflect.Type, pathsToIgnore []string, logFunc func(logEntry LogEntry, values ...interface{})) LogFunc

NewMaskingLogger returns a new Logger based on APIKit middleware.LogFunc that will mask the body content of HTTP requests and responses for a given array of field names and types.

type LogResponseStatusWriter

type LogResponseStatusWriter struct {
	http.ResponseWriter
	Status int
}

func NewLogResponseStatusWriter

func NewLogResponseStatusWriter(w http.ResponseWriter) *LogResponseStatusWriter

func (*LogResponseStatusWriter) WriteHeader

func (r *LogResponseStatusWriter) WriteHeader(status int)

type LogResponseWriter

type LogResponseWriter struct {
	LogResponseStatusWriter
	BytesWritten int64
	Body         []byte
}

LogResponseWriter represents a http.ResponseWriter with additional functionality to store response related data for a later use.

func NewLogResponseWriter

func NewLogResponseWriter(w http.ResponseWriter) *LogResponseWriter

func (*LogResponseWriter) Write

func (r *LogResponseWriter) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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