~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/gopkg.in/juju/charmstore.v5-unstable/internal/debug/handler.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2014 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
// The debug package holds various functions that may
 
5
// be used for debugging but should not be included
 
6
// in production code.
 
7
package debug // import "gopkg.in/juju/charmstore.v5-unstable/internal/debug"
 
8
 
 
9
import (
 
10
        "log"
 
11
        "net/http"
 
12
)
 
13
 
 
14
// Handler returns a new handler that wraps h
 
15
// and logs the given message with the URL path
 
16
// every time the request is invoked.
 
17
func Handler(msg string, h http.Handler) http.Handler {
 
18
        return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
 
19
                log.Printf("%s got request at URL %q; headers %q", msg, req.URL, req.Header)
 
20
                h.ServeHTTP(w, req)
 
21
        })
 
22
}