aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/gobuffalo/packr
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/gobuffalo/packr')
-rw-r--r--vendor/github.com/gobuffalo/packr/box.go49
-rw-r--r--vendor/github.com/gobuffalo/packr/builder/tmpl.go4
-rw-r--r--vendor/github.com/gobuffalo/packr/env.go24
-rw-r--r--vendor/github.com/gobuffalo/packr/go.mod10
-rw-r--r--vendor/github.com/gobuffalo/packr/go.sum22
-rw-r--r--vendor/github.com/gobuffalo/packr/packr.go19
-rw-r--r--vendor/github.com/gobuffalo/packr/walk.go63
7 files changed, 139 insertions, 52 deletions
diff --git a/vendor/github.com/gobuffalo/packr/box.go b/vendor/github.com/gobuffalo/packr/box.go
index 30eb6e2..d221101 100644
--- a/vendor/github.com/gobuffalo/packr/box.go
+++ b/vendor/github.com/gobuffalo/packr/box.go
@@ -15,6 +15,7 @@ import (
)
var (
+ // ErrResOutsideBox gets returned in case of the requested resources being outside the box
ErrResOutsideBox = errors.New("Can't find a resource outside the box")
)
@@ -51,10 +52,12 @@ type Box struct {
directories map[string]bool
}
+// AddString converts t to a byteslice and delegates to AddBytes to add to b.data
func (b Box) AddString(path string, t string) {
b.AddBytes(path, []byte(t))
}
+// AddBytes sets t in b.data by the given path
func (b Box) AddBytes(path string, t []byte) {
b.data[path] = t
}
@@ -132,14 +135,14 @@ func (b Box) find(name string) (File, error) {
bb = b.decompress(bb)
return newVirtualFile(cleanName, bb), nil
}
+ if _, ok := b.directories[cleanName]; ok {
+ return newVirtualDir(cleanName), nil
+ }
if filepath.Ext(cleanName) != "" {
// The Handler created by http.FileSystem checks for those errors and
// returns http.StatusNotFound instead of http.StatusInternalServerError.
return nil, os.ErrNotExist
}
- if _, ok := b.directories[cleanName]; ok {
- return newVirtualDir(cleanName), nil
- }
return nil, os.ErrNotExist
}
@@ -149,46 +152,6 @@ func (b Box) find(name string) (File, error) {
return fileFor(p, cleanName)
}
-type WalkFunc func(string, File) error
-
-func (b Box) Walk(wf WalkFunc) error {
- if data[b.Path] == nil {
- base, err := filepath.EvalSymlinks(filepath.Join(b.callingDir, b.Path))
- if err != nil {
- return errors.WithStack(err)
- }
- return filepath.Walk(base, func(path string, info os.FileInfo, err error) error {
- cleanName, err := filepath.Rel(base, path)
- if err != nil {
- cleanName = strings.TrimPrefix(path, base)
- }
- cleanName = filepath.ToSlash(filepath.Clean(cleanName))
- cleanName = strings.TrimPrefix(cleanName, "/")
- cleanName = filepath.FromSlash(cleanName)
- if info == nil || info.IsDir() {
- return nil
- }
-
- file, err := fileFor(path, cleanName)
- if err != nil {
- return err
- }
- return wf(cleanName, file)
- })
- }
- for n := range data[b.Path] {
- f, err := b.find(n)
- if err != nil {
- return err
- }
- err = wf(n, f)
- if err != nil {
- return err
- }
- }
- return nil
-}
-
// Open returns a File using the http.File interface
func (b Box) Open(name string) (http.File, error) {
return b.find(name)
diff --git a/vendor/github.com/gobuffalo/packr/builder/tmpl.go b/vendor/github.com/gobuffalo/packr/builder/tmpl.go
index ffe47c1..2b335ad 100644
--- a/vendor/github.com/gobuffalo/packr/builder/tmpl.go
+++ b/vendor/github.com/gobuffalo/packr/builder/tmpl.go
@@ -1,6 +1,6 @@
package builder
-var tmpl = `// Code generated by github.com/gobuffalo/packr. DO NOT EDIT
+var tmpl = `// Code generated by github.com/gobuffalo/packr. DO NOT EDIT.
package {{.Name}}
@@ -11,7 +11,7 @@ import "github.com/gobuffalo/packr"
func init() {
{{- range $box := .Boxes }}
{{- range .Files }}
- packr.PackJSONBytes("{{$box.Name}}", "{{.Name}}", "{{.Contents}}")
+ packr.PackJSONBytes("{{$box.Name}}", "{{.Name}}", "{{.Contents}}")
{{- end }}
{{- end }}
}
diff --git a/vendor/github.com/gobuffalo/packr/env.go b/vendor/github.com/gobuffalo/packr/env.go
index 2c744e7..c52e73a 100644
--- a/vendor/github.com/gobuffalo/packr/env.go
+++ b/vendor/github.com/gobuffalo/packr/env.go
@@ -1,19 +1,31 @@
package packr
import (
- "go/build"
"os"
+ "os/exec"
+ "path/filepath"
"strings"
+ "sync"
)
+var goPath = filepath.Join(os.Getenv("HOME"), "go")
+
+func init() {
+ var once sync.Once
+ once.Do(func() {
+ cmd := exec.Command("go", "env", "GOPATH")
+ b, err := cmd.CombinedOutput()
+ if err != nil {
+ return
+ }
+ goPath = strings.TrimSpace(string(b))
+ })
+}
+
// GoPath returns the current GOPATH env var
// or if it's missing, the default.
func GoPath() string {
- go_path := strings.Split(os.Getenv("GOPATH"), string(os.PathListSeparator))
- if len(go_path) == 0 || go_path[0] == "" {
- return build.Default.GOPATH
- }
- return go_path[0]
+ return goPath
}
// GoBin returns the current GO_BIN env var
diff --git a/vendor/github.com/gobuffalo/packr/go.mod b/vendor/github.com/gobuffalo/packr/go.mod
index 482c1a8..55ed22e 100644
--- a/vendor/github.com/gobuffalo/packr/go.mod
+++ b/vendor/github.com/gobuffalo/packr/go.mod
@@ -1,3 +1,11 @@
module github.com/gobuffalo/packr
-require github.com/pkg/errors v0.8.0
+require (
+ github.com/markbates/grift v1.0.1
+ github.com/pkg/errors v0.8.0
+ github.com/spf13/cobra v0.0.3
+ github.com/spf13/pflag v1.0.2 // indirect
+ github.com/stretchr/testify v1.2.2
+ golang.org/x/net v0.0.0-20180811021610-c39426892332 // indirect
+ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f
+)
diff --git a/vendor/github.com/gobuffalo/packr/go.sum b/vendor/github.com/gobuffalo/packr/go.sum
new file mode 100644
index 0000000..020cd47
--- /dev/null
+++ b/vendor/github.com/gobuffalo/packr/go.sum
@@ -0,0 +1,22 @@
+github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/markbates/grift v1.0.0/go.mod h1:6qyNEZSY8v6duE2tBtO/tPgBvxhT7g7DnQoIYpEyCfw=
+github.com/markbates/grift v1.0.1 h1:n3yUdXi+qdChTRvVCbRmD9iMLjSzv7ainzW3qYTP284=
+github.com/markbates/grift v1.0.1/go.mod h1:aC7s7OfCOzc2WCafmTm7wI3cfGFA/8opYhdTGlIAmmo=
+github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
+github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
+github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
+github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
+github.com/spf13/pflag v1.0.2 h1:Fy0orTDgHdbnzHcsOgfCN4LtHf0ec3wwtiwJqwvf3Gc=
+github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
+github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
+github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
+golang.org/x/net v0.0.0-20180808004115-f9ce57c11b24 h1:mEsFm194MmS9vCwxFy+zwu0EU7ZkxxMD1iH++vmGdUY=
+golang.org/x/net v0.0.0-20180808004115-f9ce57c11b24/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20180811021610-c39426892332 h1:efGso+ep0DjyCBJPjvoz0HI6UldX4Md2F1rZFe1ir0E=
+golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
+golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
diff --git a/vendor/github.com/gobuffalo/packr/packr.go b/vendor/github.com/gobuffalo/packr/packr.go
index d282994..6ccc6c1 100644
--- a/vendor/github.com/gobuffalo/packr/packr.go
+++ b/vendor/github.com/gobuffalo/packr/packr.go
@@ -4,6 +4,8 @@ import (
"bytes"
"compress/gzip"
"encoding/json"
+ "runtime"
+ "strings"
"sync"
)
@@ -53,3 +55,20 @@ func UnpackBytes(box string) {
defer gil.Unlock()
delete(data, box)
}
+
+func osPaths(paths ...string) []string {
+ if runtime.GOOS == "windows" {
+ for i, path := range paths {
+ paths[i] = strings.Replace(path, "/", "\\", -1)
+ }
+ }
+
+ return paths
+}
+
+func osPath(path string) string {
+ if runtime.GOOS == "windows" {
+ return strings.Replace(path, "/", "\\", -1)
+ }
+ return path
+}
diff --git a/vendor/github.com/gobuffalo/packr/walk.go b/vendor/github.com/gobuffalo/packr/walk.go
new file mode 100644
index 0000000..21f2563
--- /dev/null
+++ b/vendor/github.com/gobuffalo/packr/walk.go
@@ -0,0 +1,63 @@
+package packr
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+
+ "github.com/pkg/errors"
+)
+
+type WalkFunc func(string, File) error
+
+// Walk will traverse the box and call the WalkFunc for each file in the box/folder.
+func (b Box) Walk(wf WalkFunc) error {
+ if data[b.Path] == nil {
+ base, err := filepath.EvalSymlinks(filepath.Join(b.callingDir, b.Path))
+ if err != nil {
+ return errors.WithStack(err)
+ }
+ return filepath.Walk(base, func(path string, info os.FileInfo, err error) error {
+ cleanName, err := filepath.Rel(base, path)
+ if err != nil {
+ cleanName = strings.TrimPrefix(path, base)
+ }
+ cleanName = filepath.ToSlash(filepath.Clean(cleanName))
+ cleanName = strings.TrimPrefix(cleanName, "/")
+ cleanName = filepath.FromSlash(cleanName)
+ if info == nil || info.IsDir() {
+ return nil
+ }
+
+ file, err := fileFor(path, cleanName)
+ if err != nil {
+ return err
+ }
+ return wf(cleanName, file)
+ })
+ }
+ for n := range data[b.Path] {
+ f, err := b.find(n)
+ if err != nil {
+ return err
+ }
+ err = wf(n, f)
+ if err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+// WalkPrefix will call box.Walk and call the WalkFunc when it finds paths that have a matching prefix
+func (b Box) WalkPrefix(prefix string, wf WalkFunc) error {
+ opre := osPath(prefix)
+ return b.Walk(func(path string, f File) error {
+ if strings.HasPrefix(osPath(path), opre) {
+ if err := wf(path, f); err != nil {
+ return errors.WithStack(err)
+ }
+ }
+ return nil
+ })
+}