From 67d3450b175e483b1290df23f1bffd1215929f77 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Sat, 27 Oct 2018 08:22:14 -0400 Subject: [PATCH] back ported Find and FindString --- box.go | 35 +++++++++++++++++++++++++---------- go.mod | 1 - 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/box.go b/box.go index 1f3a6ee..946090c 100644 --- a/box.go +++ b/box.go @@ -64,27 +64,42 @@ func (b Box) AddBytes(path string, t []byte) { b.data[path] = t } -// String of the file asked for or an empty string. +// String is deprecated. Use Find instead func (b Box) String(name string) string { - return string(b.Bytes(name)) + oncer.Deprecate(0, "github.com/gobuffalo/packr#Box.String", "Use github.com/gobuffalo/packr#Box.FindString instead.") + bb, _ := b.FindString(name) + return bb } -// MustString returns either the string of the requested -// file or an error if it can not be found. +// MustString is deprecated. Use FindString instead func (b Box) MustString(name string) (string, error) { - bb, err := b.MustBytes(name) - return string(bb), err + oncer.Deprecate(0, "github.com/gobuffalo/packr#Box.MustString", "Use github.com/gobuffalo/packr#Box.FindString instead.") + return b.FindString(name) } -// Bytes of the file asked for or an empty byte slice. +// Bytes is deprecated. Use Find instead func (b Box) Bytes(name string) []byte { - bb, _ := b.MustBytes(name) + oncer.Deprecate(0, "github.com/gobuffalo/packr#Box.Bytes", "Use github.com/gobuffalo/packr#Box.Find instead.") + bb, _ := b.Find(name) return bb } -// MustBytes returns either the byte slice of the requested -// file or an error if it can not be found. +// Bytes is deprecated. Use Find instead func (b Box) MustBytes(name string) ([]byte, error) { + oncer.Deprecate(0, "github.com/gobuffalo/packr#Box.MustBytes", "Use github.com/gobuffalo/packr#Box.Find instead.") + return b.Find(name) +} + +// FindString returns either the string of the requested +// file or an error if it can not be found. +func (b Box) FindString(name string) (string, error) { + bb, err := b.Find(name) + return string(bb), err +} + +// Find returns either the byte slice of the requested +// file or an error if it can not be found. +func (b Box) Find(name string) ([]byte, error) { f, err := b.find(name) if err == nil { bb := &bytes.Buffer{} diff --git a/go.mod b/go.mod index f20ef90..30e975d 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ require ( github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/markbates/oncer v0.0.0-20181014194634-05fccaae8fc4 github.com/pkg/errors v0.8.0 - github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/cobra v0.0.3 github.com/spf13/pflag v1.0.3 // indirect github.com/stretchr/testify v1.2.2