Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultClean = QueryHide("access_token", "password", "secret")
DefaultClean is used by UseDefault constructor.
Functions ¶
func QueryHide ¶
QueryHide returns a cleanup func for use in Middleware. Each word matching a query parameter is replaced with a "..." value.
func UseDefault ¶ added in v0.2.0
func UseDefault(next http.Handler) http.HandlerFunc
UseDefault middleware logging all requests using log.Println.
Types ¶
type Middleware ¶
type Middleware struct {
// Println is used to print request method, path, response status
// and duration
Println func(...any)
// Clean is used to hide query parameters if needed
Clean func(u *url.URL) string
}
Example ¶
package main
import (
"fmt"
"net/http"
"net/url"
"github.com/gregoryv/htlog"
)
func main() {
// define a custom
customLog := htlog.Middleware{
Println: func(a ...any) {
fmt.Println(a...)
},
Clean: func(u *url.URL) string {
return u.Path
},
}
http.Handle("/", customLog.Use(serveHello()))
http.ListenAndServe(":8080", nil)
}
func serveHello() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello, world!")
}
}
func (*Middleware) Use ¶
func (m *Middleware) Use(next http.Handler) http.HandlerFunc
Click to show internal directories.
Click to hide internal directories.