mirror of https://github.com/perkeep/perkeep.git
Oh, you can embed interfaces in structs.
This commit is contained in:
parent
73587e6085
commit
bf61b6edbf
|
@ -286,26 +286,18 @@ func main() {
|
|||
const connTimeoutNanos = 15e9
|
||||
|
||||
type withTimeoutListener struct {
|
||||
l net.Listener
|
||||
net.Listener
|
||||
timeoutNanos int64
|
||||
}
|
||||
|
||||
func (wtl *withTimeoutListener) Accept() (c net.Conn, err os.Error) {
|
||||
c, err = wtl.l.Accept()
|
||||
c, err = wtl.Listener.Accept()
|
||||
if err == nil {
|
||||
c.SetTimeout(wtl.timeoutNanos)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (wtl *withTimeoutListener) Close() os.Error {
|
||||
return wtl.l.Close()
|
||||
}
|
||||
|
||||
func (wtl *withTimeoutListener) Addr() net.Addr {
|
||||
return wtl.l.Addr()
|
||||
}
|
||||
|
||||
type fixUpGitwebUrls struct {
|
||||
handler http.Handler
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"http"
|
||||
|
@ -12,14 +10,14 @@ import (
|
|||
)
|
||||
|
||||
type logRecord struct {
|
||||
http.ResponseWriter
|
||||
|
||||
time *time.Time
|
||||
ip, method, rawpath string
|
||||
responseBytes int64
|
||||
responseStatus int
|
||||
userAgent, referer string
|
||||
proto string // "HTTP/1.1"
|
||||
|
||||
rw http.ResponseWriter
|
||||
}
|
||||
|
||||
type logHandler struct {
|
||||
|
@ -57,7 +55,7 @@ func (h *logHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
|||
referer: r.Referer,
|
||||
responseStatus: http.StatusOK,
|
||||
proto: r.Proto,
|
||||
rw: rw,
|
||||
ResponseWriter: rw,
|
||||
}
|
||||
h.handler.ServeHTTP(lr, r)
|
||||
h.ch <- lr
|
||||
|
@ -117,34 +115,12 @@ func (h *logHandler) logFromChannel() {
|
|||
}
|
||||
|
||||
func (lr *logRecord) Write(p []byte) (int, os.Error) {
|
||||
written, err := lr.rw.Write(p)
|
||||
written, err := lr.ResponseWriter.Write(p)
|
||||
lr.responseBytes += int64(written)
|
||||
return written, err
|
||||
}
|
||||
|
||||
func (lr *logRecord) WriteHeader(status int) {
|
||||
lr.responseStatus = status
|
||||
lr.rw.WriteHeader(status)
|
||||
}
|
||||
|
||||
// Boring proxies: (seems like I should be able to use embedding somehow...)
|
||||
|
||||
func (lr *logRecord) RemoteAddr() string {
|
||||
return lr.rw.RemoteAddr()
|
||||
}
|
||||
|
||||
func (lr *logRecord) UsingTLS() bool {
|
||||
return lr.rw.UsingTLS()
|
||||
}
|
||||
|
||||
func (lr *logRecord) SetHeader(k, v string) {
|
||||
lr.rw.SetHeader(k, v)
|
||||
}
|
||||
|
||||
func (lr *logRecord) Flush() {
|
||||
lr.rw.Flush()
|
||||
}
|
||||
|
||||
func (lr *logRecord) Hijack() (io.ReadWriteCloser, *bufio.ReadWriter, os.Error) {
|
||||
return lr.rw.Hijack()
|
||||
lr.ResponseWriter.WriteHeader(status)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue