From 73d13c2fc10ea0bd1a720c886272b3c0b9f35966 Mon Sep 17 00:00:00 2001 From: Ben Tranter Date: Mon, 19 Feb 2018 15:10:47 -0500 Subject: [PATCH 1/4] Format nil time.Time's without panicking Fixes #82 Updates the DateFormat function to return an empty string if the provided `*time.Time` is `nil`, instead of panicking. --- app/utils/date.go | 4 ++++ app/utils/date_test.go | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/utils/date.go b/app/utils/date.go index 0230a8b..4ec0350 100644 --- a/app/utils/date.go +++ b/app/utils/date.go @@ -56,6 +56,10 @@ var conversion = map[rune]string{ // %z numbers representing the timezone, ex: "-0700" // %L milliseconds, ex: ".000" func DateFormat(t *time.Time, format string) string { + if t == nil { + return "" + } + retval := make([]byte, 0, len(format)) for i, ni := 0, 0; i < len(format); i = ni + 2 { ni = strings.IndexByte(format[i:], '%') diff --git a/app/utils/date_test.go b/app/utils/date_test.go index 348a271..a1c22c6 100644 --- a/app/utils/date_test.go +++ b/app/utils/date_test.go @@ -2,9 +2,10 @@ package utils import ( "fmt" - . "github.com/smartystreets/goconvey/convey" "testing" "time" + + . "github.com/smartystreets/goconvey/convey" ) func ExampleDateFormat() { @@ -22,4 +23,11 @@ func TestDateFormat(t *testing.T) { So(dateFmt, ShouldEqual, "2009-11-10 23:00") }) }) + + Convey("It should not panic when trying to format nil dates", t, func() { + dateFmt := DateFormat(nil, "%Y-%m-%d %H:%M") + Convey("Test DateFormat", func() { + So(dateFmt, ShouldEqual, "") + }) + }) } From a08964ea00c686c2f16a2619f15aabcadb3aa564 Mon Sep 17 00:00:00 2001 From: Ben Tranter Date: Mon, 19 Feb 2018 15:39:15 -0500 Subject: [PATCH 2/4] Update Travis to use modern versions of Go --- .travis.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 85cc0b8..5bcc905 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,11 @@ language: go go: - - 1.4 - - 1.5 - - 1.6 + - 1.7 + - 1.8 + - 1.9 + - "1.10" + - tip install: - go get -t ./... From 1c5b0c0115a344caaf78725b59f5920fc2765ce7 Mon Sep 17 00:00:00 2001 From: Ben Tranter Date: Mon, 19 Feb 2018 15:41:38 -0500 Subject: [PATCH 3/4] Update Travis and tests for latest Go versions --- app/handler/auth_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/handler/auth_test.go b/app/handler/auth_test.go index 3f08cc0..820c151 100644 --- a/app/handler/auth_test.go +++ b/app/handler/auth_test.go @@ -187,8 +187,8 @@ func TestUserWithoutAuthentication(t *testing.T) { ctx := mockContext(nil, "GET", "/admin/") ctx.App.ServeHTTP(ctx.Response, ctx.Request) - Convey("Status code should be 301 redirection", func() { - So(ctx.Response.(*httptest.ResponseRecorder).Code, ShouldEqual, 301) + Convey("Status code should be 302 redirection", func() { + So(ctx.Response.(*httptest.ResponseRecorder).Code, ShouldEqual, 302) }) }) From 2fefd0a6e0f3252a91ba70a829b5bde97397175b Mon Sep 17 00:00:00 2001 From: Ben Tranter Date: Mon, 19 Feb 2018 15:58:15 -0500 Subject: [PATCH 4/4] Switch Println to Printf Go 1.10 treats Println's with formatting directives differently than previous versions apparently, so this fixes the current build issues. --- app/utils/file.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/utils/file.go b/app/utils/file.go index 5446169..181a45d 100644 --- a/app/utils/file.go +++ b/app/utils/file.go @@ -107,13 +107,13 @@ func CopyDir(source string, dest string) (err error) { if entry.IsDir() { err = CopyDir(sfp, dfp) if err != nil { - log.Println("[Error]: %v", err) + log.Printf("[Error]: %v", err) } } else { // perform copy err = CopyFile(sfp, dfp) if err != nil { - log.Println("[Error]: %v", err) + log.Printf("[Error]: %v", err) } }