diff --git a/go.mod b/go.mod index 882198ec9..e921f880d 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( github.com/rivo/uniseg v0.4.7 github.com/sahilm/fuzzy v0.1.0 github.com/samber/lo v1.31.0 - github.com/sanity-io/litter v1.5.2 + github.com/sanity-io/litter v1.5.8 github.com/sasha-s/go-deadlock v0.3.6 github.com/sirupsen/logrus v1.9.3 github.com/spf13/afero v1.15.0 diff --git a/go.sum b/go.sum index d004607cb..99bf2a9cd 100644 --- a/go.sum +++ b/go.sum @@ -102,8 +102,8 @@ github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI= github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= github.com/samber/lo v1.31.0 h1:Sfa+/064Tdo4SvlohQUQzBhgSer9v/coGvKQI/XLWAM= github.com/samber/lo v1.31.0/go.mod h1:HLeWcJRRyLKp3+/XBJvOrerCQn9mhdKMHyd7IRlgeQ8= -github.com/sanity-io/litter v1.5.2 h1:AnC8s9BMORWH5a4atZ4D6FPVvKGzHcnc5/IVTa87myw= -github.com/sanity-io/litter v1.5.2/go.mod h1:5Z71SvaYy5kcGtyglXOC9rrUi3c1E8CamFWjQsazTh0= +github.com/sanity-io/litter v1.5.8 h1:uM/2lKrWdGbRXDrIq08Lh9XtVYoeGtcQxk9rtQ7+rYg= +github.com/sanity-io/litter v1.5.8/go.mod h1:9gzJgR2i4ZpjZHsKvUXIRQVk7P+yM3e+jAF7bU2UI5U= github.com/sasha-s/go-deadlock v0.3.6 h1:TR7sfOnZ7x00tWPfD397Peodt57KzMDo+9Ae9rMiUmw= github.com/sasha-s/go-deadlock v0.3.6/go.mod h1:CUqNyyvMxTyjFqDT7MRg9mb4Dv/btmGTqSR+rky/UXo= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= diff --git a/vendor/github.com/sanity-io/litter/.travis.yml b/vendor/github.com/sanity-io/litter/.travis.yml deleted file mode 100644 index ec9381c95..000000000 --- a/vendor/github.com/sanity-io/litter/.travis.yml +++ /dev/null @@ -1,7 +0,0 @@ -arch: -- amd64 -- ppc64le - -language: go -go: -- 1.14.x diff --git a/vendor/github.com/sanity-io/litter/dump.go b/vendor/github.com/sanity-io/litter/dump.go index 3dfbb9dbd..d830c5e9d 100644 --- a/vendor/github.com/sanity-io/litter/dump.go +++ b/vendor/github.com/sanity-io/litter/dump.go @@ -11,6 +11,7 @@ import ( "sort" "strconv" "strings" + "time" ) var ( @@ -40,6 +41,9 @@ type Options struct { // when it's safe. This is useful for diffing two structures, where pointer variables would cause // false changes. However, circular graphs are still detected and elided to avoid infinite output. DisablePointerReplacement bool + + // FormatTime, if true, will format [time.Time] values. + FormatTime bool } // Config is the default config used when calling Dump @@ -59,6 +63,7 @@ type dumpState struct { parentPointers ptrmap currentPointer *ptrinfo homePackageRegexp *regexp.Regexp + timeFormatter func(t time.Time) string } func (s *dumpState) write(b []byte) { @@ -129,6 +134,14 @@ func (s *dumpState) dumpSlice(v reflect.Value) { } func (s *dumpState) dumpStruct(v reflect.Value) { + if v.CanInterface() { + val := v.Interface() + if t, ok := val.(time.Time); ok && s.timeFormatter != nil { + s.writeString(s.timeFormatter(t)) + return + } + } + dumpPreamble := func() { s.dumpType(v) s.write([]byte("{")) @@ -246,7 +259,6 @@ func (s *dumpState) dumpChan(v reflect.Value) { } func (s *dumpState) dumpCustom(v reflect.Value, buf *bytes.Buffer) { - // Dump the type s.dumpType(v) @@ -293,6 +305,8 @@ func (s *dumpState) dump(value interface{}) { s.dumpVal(v) } +var dumperType = reflect.TypeOf((*Dumper)(nil)).Elem() + func (s *dumpState) descendIntoPossiblePointer(value reflect.Value, f func()) { canonicalize := true if isPointerValue(value) { @@ -345,7 +359,6 @@ func (s *dumpState) dumpVal(value reflect.Value) { } // Handle custom dumpers - dumperType := reflect.TypeOf((*Dumper)(nil)).Elem() if v.Type().Implements(dumperType) { s.descendIntoPossiblePointer(v, func() { // Run the custom dumper buffering the output @@ -457,13 +470,23 @@ func (s *dumpState) pointerFor(v reflect.Value) (*ptrinfo, bool) { } // prepares a new state object for dumping the provided value -func newDumpState(value interface{}, options *Options, writer io.Writer) *dumpState { +func newDumpState(value reflect.Value, options *Options, writer io.Writer) *dumpState { result := &dumpState{ config: options, - pointers: mapReusedPointers(reflect.ValueOf(value)), + pointers: mapReusedPointers(value), w: writer, } + if options.FormatTime { + result.timeFormatter = func(t time.Time) string { + t = t.In(time.UTC) + return fmt.Sprintf( + `time.Date(%d, %d, %d, %d, %d, %d, %d, time.UTC)`, + t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), + ) + } + } + if options.HomePackage != "" { result.homePackageRegexp = regexp.MustCompile(fmt.Sprintf("\\b%s\\.", options.HomePackage)) } @@ -471,12 +494,17 @@ func newDumpState(value interface{}, options *Options, writer io.Writer) *dumpSt return result } -// Dump a value to stdout +// Dump a value to stdout. func Dump(value ...interface{}) { (&Config).Dump(value...) } -// Sdump dumps a value to a string +// D dumps a value to stdout, and is a shorthand for [Dump]. +func D(value ...interface{}) { + Dump(value...) +} + +// Sdump dumps a value to a string. func Sdump(value ...interface{}) string { return (&Config).Sdump(value...) } @@ -484,7 +512,7 @@ func Sdump(value ...interface{}) string { // Dump a value to stdout according to the options func (o Options) Dump(values ...interface{}) { for i, value := range values { - state := newDumpState(value, &o, os.Stdout) + state := newDumpState(reflect.ValueOf(value), &o, os.Stdout) if i > 0 { state.write([]byte(o.Separator)) } @@ -500,7 +528,7 @@ func (o Options) Sdump(values ...interface{}) string { if i > 0 { _, _ = buf.Write([]byte(o.Separator)) } - state := newDumpState(value, &o, buf) + state := newDumpState(reflect.ValueOf(value), &o, buf) state.dump(value) } return buf.String() diff --git a/vendor/github.com/sanity-io/litter/pointers.go b/vendor/github.com/sanity-io/litter/pointers.go index 2c57d79ae..74b9a0f54 100644 --- a/vendor/github.com/sanity-io/litter/pointers.go +++ b/vendor/github.com/sanity-io/litter/pointers.go @@ -118,8 +118,7 @@ func (pv *pointerVisitor) consider(v reflect.Value) { // Now descend into any children of this value switch v.Kind() { case reflect.Slice, reflect.Array: - numEntries := v.Len() - for i := 0; i < numEntries; i++ { + for i := 0; i < v.Len(); i++ { pv.consider(v.Index(i)) } @@ -136,6 +135,7 @@ func (pv *pointerVisitor) consider(v reflect.Value) { options: &Config, }) for _, key := range keys { + pv.consider(key) pv.consider(v.MapIndex(key)) } diff --git a/vendor/modules.txt b/vendor/modules.txt index 5e7b72d2f..bb2361246 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -152,8 +152,8 @@ github.com/sahilm/fuzzy # github.com/samber/lo v1.31.0 ## explicit; go 1.18 github.com/samber/lo -# github.com/sanity-io/litter v1.5.2 -## explicit; go 1.14 +# github.com/sanity-io/litter v1.5.8 +## explicit; go 1.16 github.com/sanity-io/litter # github.com/sasha-s/go-deadlock v0.3.6 ## explicit