A simple HTTP access logger for golang

Written by
reddit
Link to Post

https://www.reddit.com/r/golang/comments/bnzcxy/a_simple_http_access_logger_for_golang/ by 

go-accesslog

Usage:

func AccessLog(cb func(call *accesslog.Call)) func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { // before request,install ResponseWriter proxy call := &accesslog.Call{} rwProxy := accesslog.NewResponseRecorder(rw, true) accesslog.Before(call, r) next.ServeHTTP(rwProxy, r) // after request and callback accesslog.After(call, rwProxy, r) cb(call) }) } } 

submitted by /u/timesmaster
[link] [comments]

Article Tags:
· ·
Article Categories:
reddit

Leave a Reply