Skip to content

Commit

Permalink
text: Remove dependency on github.com/go-openapi/strfmt (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
titanous authored May 27, 2020
1 parent 3a6002f commit efc0c98
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 42 deletions.
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ module github.com/jedib0t/go-pretty/v6
go 1.13

require (
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 // indirect
github.com/go-openapi/errors v0.19.0 // indirect
github.com/go-openapi/strfmt v0.19.0
github.com/mailru/easyjson v0.0.0-20190403194419-1ea4449da983 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/mattn/go-runewidth v0.0.9
github.com/pkg/profile v1.2.1
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.2.2
golang.org/x/sys v0.0.0-20180816055513-1c9583448a9c
)
26 changes: 0 additions & 26 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,31 +1,7 @@
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf h1:eg0MeVzsP1G42dRafH3vf+al2vQIJU0YHX+1Tw87oco=
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 h1:DujepqpGd1hyOd7aW59XpK7Qymp8iy83xq74fLr21is=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/go-openapi/errors v0.17.0/go.mod h1:LcZQpmvG4wyF5j4IhA73wkLFQg+QJXOQHVjmcZxhka0=
github.com/go-openapi/errors v0.19.0 h1:guf3T2lnCBKlODmERt4T9GtMWRpJOikgKGyIvi0xcb8=
github.com/go-openapi/errors v0.19.0/go.mod h1:LcZQpmvG4wyF5j4IhA73wkLFQg+QJXOQHVjmcZxhka0=
github.com/go-openapi/strfmt v0.19.0 h1:0Dn9qy1G9+UJfRU7TR8bmdGxb4uifB7HNrJjOnV0yPk=
github.com/go-openapi/strfmt v0.19.0/go.mod h1:+uW+93UVvGGq2qGaZxdDeJqSAqBqBdl+ZPMF/cC8nDY=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190403194419-1ea4449da983 h1:wL11wNW7dhKIcRCHSm4sHKPWz0tt4mwBsVodG7+Xyqg=
github.com/mailru/easyjson v0.0.0-20190403194419-1ea4449da983/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/pkg/profile v1.2.1 h1:F++O52m40owAmADcojzM+9gyjmMOY/T4oYJkgFDH8RE=
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -34,5 +10,3 @@ github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/sys v0.0.0-20180816055513-1c9583448a9c h1:uHnKXcvx6SNkuwC+nrzxkJ+TpPwZOtumbhWrrOYN5YA=
golang.org/x/sys v0.0.0-20180816055513-1c9583448a9c/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
10 changes: 3 additions & 7 deletions text/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"strconv"
"strings"
"time"

"github.com/go-openapi/strfmt"
)

// Transformer related constants
Expand Down Expand Up @@ -119,8 +117,8 @@ func NewJSONTransformer(prefix string, indent string) Transformer {
}

// NewTimeTransformer returns a Transformer that can format a timestamp (a
// time.Time or strfmt.DateTime object) into a well-defined time format defined
// using the provided layout (ex.: time.RFC3339).
// time.Time) into a well-defined time format defined using the provided layout
// (ex.: time.RFC3339).
//
// If a non-nil location value is provided, the time will be localized to that
// location (use time.Local to get localized timestamps).
Expand All @@ -138,9 +136,7 @@ func NewTimeTransformer(layout string, location *time.Location) Transformer {
}

rsp := fmt.Sprint(val)
if valDate, ok := val.(strfmt.DateTime); ok {
rsp = formatTime(time.Time(valDate))
} else if valTime, ok := val.(time.Time); ok {
if valTime, ok := val.(time.Time); ok {
rsp = formatTime(valTime)
} else if valStr, ok := val.(string); ok {
if valTime, err := time.Parse(time.RFC3339, valStr); err == nil {
Expand Down
5 changes: 0 additions & 5 deletions text/transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"testing"
"time"

"github.com/go-openapi/strfmt"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -143,31 +142,27 @@ func TestNewTimeTransformer(t *testing.T) {
inStr := "2010-11-12T13:14:15-07:00"
inTime, err := time.Parse(time.RFC3339, inStr)
assert.Nil(t, err)
inDateTime := strfmt.DateTime(inTime)

location, err := time.LoadLocation("America/Los_Angeles")
assert.Nil(t, err)
transformer := NewTimeTransformer(time.RFC3339, location)
expected := "2010-11-12T12:14:15-08:00"
assert.Equal(t, expected, transformer(inStr))
assert.Equal(t, expected, transformer(inTime))
assert.Equal(t, expected, transformer(inDateTime))

location, err = time.LoadLocation("Asia/Singapore")
assert.Nil(t, err)
transformer = NewTimeTransformer(time.UnixDate, location)
expected = "Sat Nov 13 04:14:15 +08 2010"
assert.Equal(t, expected, transformer(inStr))
assert.Equal(t, expected, transformer(inTime))
assert.Equal(t, expected, transformer(inDateTime))

location, err = time.LoadLocation("Europe/London")
assert.Nil(t, err)
transformer = NewTimeTransformer(time.RFC3339, location)
expected = "2010-11-12T20:14:15Z"
assert.Equal(t, expected, transformer(inStr))
assert.Equal(t, expected, transformer(inTime))
assert.Equal(t, expected, transformer(inDateTime))
}

func TestNewUnixTimeTransformer(t *testing.T) {
Expand Down

0 comments on commit efc0c98

Please sign in to comment.