httplog

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}
Example
// create new logger using the default `slog.Logger`.
hl := NewLogger(slog.Default())

// create new mux so we can easily forward it with the middleware.
mux := http.NewServeMux()

// handle all requests with a "Hello World" response.
mux.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
	writer.Write([]byte("Hello World"))
})

// listen and serve using the logger as a middleware.
err := http.ListenAndServe(":8080", hl.Handler(mux))
if err != nil {
	panic(err)
}
Output:

func NewLogger

func NewLogger(sl *slog.Logger) Logger

func (*Logger) Handler

func (l *Logger) Handler(n http.Handler) http.Handler

type ResponseWriter

type ResponseWriter struct {
	Writer http.ResponseWriter
	// contains filtered or unexported fields
}

func (*ResponseWriter) Header

func (w *ResponseWriter) Header() http.Header

func (*ResponseWriter) Write

func (w *ResponseWriter) Write(p []byte) (int, error)

func (*ResponseWriter) WriteHeader

func (w *ResponseWriter) WriteHeader(s int)

Jump to

Keyboard shortcuts

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