Skip to content

Instantly share code, notes, and snippets.

@arran4
Created August 19, 2020 06:22
Show Gist options
  • Save arran4/3f78132dd9a0dd08c322f3b06e990bb8 to your computer and use it in GitHub Desktop.
Save arran4/3f78132dd9a0dd08c322f3b06e990bb8 to your computer and use it in GitHub Desktop.
Keep on writing something like this.
package main
import (
"bytes"
"io"
"log"
"net/http"
)
type LogHandler struct {
logChan chan *bytes.Buffer
}
func (l LogHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
b := bytes.NewBuffer(nil)
request.Write(b)
io.Copy(b, request.Body)
l.logChan <- b
}
func main() {
logChan := make(chan *bytes.Buffer)
go func() {
for b := range logChan {
log.Printf("==================\n%s\n\n==============", b.String())
}
}()
http.ListenAndServe(":9090", &LogHandler{logChan: logChan})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment