Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ language: go
go:
- 1.3
- 1.4
- 1.5.2
- 1.5
- 1.6
- 1.7
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ type Reminder struct {
}

type Impl struct {
DB gorm.DB
DB *gorm.DB
}

func (i *Impl) InitDB() {
Expand Down
11 changes: 8 additions & 3 deletions rest/access_log_apache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"log"
"net"
"os"
"strings"
"text/template"
Expand Down Expand Up @@ -131,7 +132,10 @@ func (mw *AccessLogApacheMiddleware) convertFormat() {
return fmt.Sprintf("%d", value)
},
"microseconds": func(dur *time.Duration) string {
return fmt.Sprintf("%d", dur.Nanoseconds()/1000)
if dur != nil {
return fmt.Sprintf("%d", dur.Nanoseconds()/1000)
}
return ""
},
"statusCodeColor": func(statusCode int) string {
if statusCode >= 400 && statusCode < 500 {
Expand Down Expand Up @@ -195,8 +199,9 @@ func (u *accessLogUtil) StartTime() *time.Time {
func (u *accessLogUtil) ApacheRemoteAddr() string {
remoteAddr := u.R.RemoteAddr
if remoteAddr != "" {
parts := strings.SplitN(remoteAddr, ":", 2)
return parts[0]
if ip, _, err := net.SplitHostPort(remoteAddr); err == nil {
return ip
}
}
return ""
}
Expand Down
6 changes: 6 additions & 0 deletions rest/gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ func (mw *GzipMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc {
canGzip := strings.Contains(r.Header.Get("Accept-Encoding"), "gzip")
// client accepts gzip ?
writer := &gzipResponseWriter{w, false, canGzip, nil}
defer func() {
// need to close gzip writer
if writer.gzipWriter != nil {
writer.gzipWriter.Close()
}
}()
// call the handler with the wrapped writer
h(writer, r)
}
Expand Down
4 changes: 2 additions & 2 deletions rest/recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func TestRecorderAndGzipMiddleware(t *testing.T) {
}
bytesWritten := r.Env["BYTES_WRITTEN"].(int64)
// Yes, the gzipped version actually takes more space.
if bytesWritten != 28 {
t.Errorf("BYTES_WRITTEN 28 expected, got %d", bytesWritten)
if bytesWritten != 41 {
t.Errorf("BYTES_WRITTEN 41 expected, got %d", bytesWritten)
}
}
}))
Expand Down