An open API service indexing awesome lists of open source software.

https://github.com/timestee/go-accesslog

A simple HTTP access log for golang.
https://github.com/timestee/go-accesslog

access-logs golang http http-server logger middleware

Last synced: 10 days ago
JSON representation

A simple HTTP access log for golang.

Awesome Lists containing this project

README

          

# go-accesslog 
[![Build Status](https://travis-ci.org/timestee/go-accesslog.svg?branch=master)](https://travis-ci.org/timestee/go-accesslog) [![Go Walker](https://gowalker.org/api/v1/badge)](https://gowalker.org/github.com/timestee/go-accesslog)  [![GoDoc](https://godoc.org/github.com/timestee/go-accesslog?status.svg)](https://godoc.org/github.com/timestee/go-accesslog)[![Sourcegraph](https://sourcegraph.com/github.com/timestee/go-accesslog/-/badge.svg)](https://sourcegraph.com/github.com/timestee/go-accesslog?badge)

A simple HTTP access logger for golang.

Usage:

```golang
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)
})
}
}
```