Strip a newline and add more text to a Go bytes.Buffer
I believe you are over-complicating the handler function by introducing the deferred function with the start time closure. Additionally, you are performing 2 writes to accomplish the logging, when one would be better.

So, Why have the "defer"? This code:


    var b bytes.Buffer
    hand := handlers.CombinedLoggingHandler(&amp;b, h)

    defer func(start time.Time) {
        prefix := bytes.TrimRight(b.Bytes(), "\n")
        os.Stdout.Write(prefix)
        fmt.Printf(" completed in %v\n", time.Since(start))
    }(time.Now())

    hand.ServeHTTP(res, req)



would be simpler to understand as:

    start := time.Now()
    var b bytes.Buffer
    hand := handlers.CombinedLoggingHandler(&amp;b, h)

    hand.ServeHTTP(res, req)

    prefix := bytes.TrimRight(b.Bytes(), "\n")
    os.Stdout.Write(prefix)
    fmt.Printf(" completed in %v\n", time.Since(start))


Then, in addition, I would manipulate the bytes to trim and add the completion message, and then output them...., so I would change the last part of the code to be something like:

    msg := bytes.TrimRight(b.Bytes(), "\n")
    msg := append(msg, []byte(fmt.Sprintf(" completed in %v\n", time.Since(start)...)
    os.Stdout.Write(msg)


That still irks me a bit, because i don't like the os.Stdout.Write being a constant value in there.... I would make that a parameter somehow, or a constant of some sort....

var logDest io.Writer = os.Stdout