Skip to content

Commit

Permalink
Merge pull request #42 from xushiwei/q
Browse files Browse the repository at this point in the history
x/http/tracer.Tee: change prototype
  • Loading branch information
xushiwei authored Aug 24, 2023
2 parents 29fc16d + 1804339 commit c0ab963
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions http/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,26 @@ import (
// -------------------------------------------------------------------------------

type teeResponseWriter struct {
w []http.ResponseWriter
a, b http.ResponseWriter
}

func (p *teeResponseWriter) Header() http.Header {
return p.w[0].Header()
return p.a.Header()
}

func (p *teeResponseWriter) Write(buf []byte) (n int, err error) {
n, err = p.w[0].Write(buf)
for _, w := range p.w[1:] {
w.Write(buf)
}
n, err = p.a.Write(buf)
p.b.Write(buf)
return
}

func (p *teeResponseWriter) WriteHeader(statusCode int) {
p.w[0].WriteHeader(statusCode)
for _, w := range p.w[1:] {
w.WriteHeader(statusCode)
}
p.a.WriteHeader(statusCode)
p.b.WriteHeader(statusCode)
}

func Tee(w ...http.ResponseWriter) http.ResponseWriter {
return &teeResponseWriter{w}
func Tee(a, b http.ResponseWriter) http.ResponseWriter {
return &teeResponseWriter{a, b}
}

// -------------------------------------------------------------------------------
Expand Down

0 comments on commit c0ab963

Please sign in to comment.