zhttp

package
v7.5.4 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendAccessLog

func AppendAccessLog(req *http.Request, f AccessLogCallback)

AppendAccessLog adds a callback function which will be invoked to amend the access log with additional fields.

func AppendAccessLogContext

func AppendAccessLogContext(ctx context.Context, f AccessLogCallback)

AppendAccessLog adds a callback function which will be invoked to amend the access log with additional fields.

func DontLog

func DontLog(req *http.Request)

DontLog marks that the current request should not generate an access log entry

func LoggingMiddleware

func LoggingMiddleware(opts ...LoggingOption) func(http.Handler) http.Handler

LoggingMiddleware creates a logging context for each request, and emits an access log entry at the completion of the request.

func RecoveryMiddleware

func RecoveryMiddleware(next http.Handler) http.Handler

RecoveryMiddleware catches panics, logs the error, and writes a generic Internal Server Error response

func SetupLogging

func SetupLogging(levelName, logFile string) error

SetupLogging initializes zerolog with reasonable defaults

func StripPort

func StripPort(clientIP string) string

StripPort returns just the IP part from e.g. Request.RemoteAddr

func WriteUnhandledError

func WriteUnhandledError(w http.ResponseWriter, req *http.Request, err error, traceback string)

WriteUnhandledError writes a generic 500 Internal Server Error response while logging the actual unhandled error and optional traceback

Types

type AccessLogCallback

type AccessLogCallback func(*zerolog.Event)

type Logger

type Logger struct {
	http.ResponseWriter

	Now func() time.Time
	// contains filtered or unexported fields
}

Logger wraps a ResponseWriter and records the resulting status code and how many bytes are written

func (*Logger) CloseNotify

func (l *Logger) CloseNotify() <-chan bool

CloseNotify wraps a nested CloseNotifier

func (*Logger) Flush

func (l *Logger) Flush()

Flush wraps a nested Flusher

func (*Logger) Hijack

func (l *Logger) Hijack() (net.Conn, *bufio.ReadWriter, error)

Hijack wraps a nested Hijacker

func (*Logger) Length

func (l *Logger) Length() int64

Length returns the number of bytes written

func (*Logger) Push

func (l *Logger) Push(target string, opts *http.PushOptions) error

Push wraps a nested Pusher

func (*Logger) Started

func (l *Logger) Started() time.Time

Started returns the time at which headers were written

func (*Logger) Status

func (l *Logger) Status() int

Status returns the response status

func (*Logger) Write

func (l *Logger) Write(d []byte) (size int, err error)

Write implements ResponseWriter

func (*Logger) WriteHeader

func (l *Logger) WriteHeader(status int)

WriteHeader implements ResponseWriter

type LoggingOption

type LoggingOption func(*loggingConfig)

func WithLogger

func WithLogger(logger zerolog.Logger) LoggingOption

WithLogger sets the base logger for the middleware

Jump to

Keyboard shortcuts

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