Import upstream version 2.8.1
Kali Janitor
2 years ago
0 | name: Tests | |
1 | on: [push, pull_request] | |
2 | jobs: | |
3 | ||
4 | tests: | |
5 | name: ${{matrix.go-version}} ${{matrix.os}} | |
6 | runs-on: ${{ matrix.os }} | |
7 | strategy: | |
8 | matrix: | |
9 | go-version: [1.12.x, 1.13.x] | |
10 | os: [macos-latest, windows-latest, ubuntu-latest] | |
11 | steps: | |
12 | - name: Checkout Code | |
13 | uses: actions/checkout@v1 | |
14 | with: | |
15 | fetch-depth: 1 | |
16 | - name: Test v1 | |
17 | run: | | |
18 | go get -t -v ./... | |
19 | go test -race ./... | |
20 | go install -v ./packr | |
21 | - name: Test v2 | |
22 | run: | | |
23 | cd v2 | |
24 | go get -t -v ./... | |
25 | go test -race ./... | |
26 | go install -v ./packr2⏎ |
0 | **NOTICE: Please consider migrating your projects to [github.com/markbates/pkger](https://github.com/markbates/pkger). It has an idiomatic API, minimal dependencies, a stronger test suite (tested directly against the std lib counterparts), transparent tooling, and more.** | |
1 | ||
2 | https://blog.gobuffalo.io/introducing-pkger-static-file-embedding-in-go-1ce76dc79c65 | |
3 | ||
4 | ||
0 | 5 | # packr (v1) |
1 | 6 | |
2 | 7 | [![GoDoc](https://godoc.org/github.com/gobuffalo/packr?status.svg)](https://godoc.org/github.com/gobuffalo/packr) |
39 | 44 | html, err := box.FindString("index.html") |
40 | 45 | |
41 | 46 | // Get the []byte representation of a file, or an error if it doesn't exist: |
42 | html, err := box.FindBytes("index.html") | |
47 | html, err := box.Find("index.html") | |
43 | 48 | ``` |
44 | 49 | |
45 | 50 | ### What is a Box? |
0 | variables: | |
1 | GOBIN: "$(GOPATH)/bin" # Go binaries path | |
2 | GOPATH: "$(system.defaultWorkingDirectory)/gopath" # Go workspace path | |
3 | modulePath: "$(GOPATH)/src/github.com/$(build.repository.name)" # Path to the module"s code | |
4 | ||
5 | jobs: | |
6 | - job: Windows | |
7 | pool: | |
8 | vmImage: "vs2017-win2016" | |
9 | strategy: | |
10 | matrix: | |
11 | go 1.10: | |
12 | go_version: "1.10" | |
13 | go 1.11 (on): | |
14 | go_version: "1.11.5" | |
15 | GO111MODULE: "on" | |
16 | go 1.11 (off): | |
17 | go_version: "1.11.5" | |
18 | GO111MODULE: "off" | |
19 | go 1.12 (on): | |
20 | go_version: "1.12" | |
21 | GO111MODULE: "on" | |
22 | go 1.12 (off): | |
23 | go_version: "1.12" | |
24 | GO111MODULE: "off" | |
25 | steps: | |
26 | - template: azure-tests.yml | |
27 | ||
28 | - job: macOS | |
29 | pool: | |
30 | vmImage: "macOS-10.13" | |
31 | strategy: | |
32 | matrix: | |
33 | go 1.10: | |
34 | go_version: "1.10" | |
35 | go 1.11 (on): | |
36 | go_version: "1.11.5" | |
37 | GO111MODULE: "on" | |
38 | go 1.11 (off): | |
39 | go_version: "1.11.5" | |
40 | GO111MODULE: "off" | |
41 | go 1.12 (on): | |
42 | go_version: "1.12" | |
43 | GO111MODULE: "on" | |
44 | go 1.12 (off): | |
45 | go_version: "1.12" | |
46 | GO111MODULE: "off" | |
47 | steps: | |
48 | - template: azure-tests.yml | |
49 | ||
50 | - job: Linux | |
51 | pool: | |
52 | vmImage: "ubuntu-16.04" | |
53 | strategy: | |
54 | matrix: | |
55 | go 1.10: | |
56 | go_version: "1.10" | |
57 | go 1.11 (on): | |
58 | go_version: "1.11.5" | |
59 | GO111MODULE: "on" | |
60 | go 1.11 (off): | |
61 | go_version: "1.11.5" | |
62 | GO111MODULE: "off" | |
63 | go 1.12 (on): | |
64 | go_version: "1.12" | |
65 | GO111MODULE: "on" | |
66 | go 1.12 (off): | |
67 | go_version: "1.12" | |
68 | GO111MODULE: "off" | |
69 | steps: | |
70 | - template: azure-tests.yml |
0 | steps: | |
1 | - task: GoTool@0 | |
2 | inputs: | |
3 | version: $(go_version) | |
4 | - task: Bash@3 | |
5 | inputs: | |
6 | targetType: inline | |
7 | script: | | |
8 | mkdir -p "$(GOBIN)" | |
9 | mkdir -p "$(GOPATH)/pkg" | |
10 | mkdir -p "$(modulePath)" | |
11 | shopt -s extglob | |
12 | mv !(gopath) "$(modulePath)" | |
13 | displayName: "Setup Go Workspace" | |
14 | - script: | | |
15 | go get -t -v ./... | |
16 | go test -race ./... | |
17 | go install -v ./packr | |
18 | cd v2 | |
19 | go get -t -v ./... | |
20 | go test -race ./... | |
21 | go install -v ./packr2 | |
22 | workingDirectory: "$(modulePath)" | |
23 | displayName: "Tests" |
10 | 10 | func init() { |
11 | 11 | {{- range $box := .Boxes }} |
12 | 12 | {{- range .Files }} |
13 | packr.PackJSONBytes("{{$box.Name}}", "{{.Name}}", "{{.Contents}}") | |
13 | _ = packr.PackJSONBytes("{{$box.Name}}", "{{.Name}}", "{{.Contents}}") | |
14 | 14 | {{- end }} |
15 | 15 | {{- end }} |
16 | 16 | } |
4 | 4 | require ( |
5 | 5 | github.com/gobuffalo/envy v1.7.0 |
6 | 6 | github.com/gobuffalo/packd v0.3.0 |
7 | github.com/gobuffalo/packr/v2 v2.5.1 | |
7 | github.com/gobuffalo/packr/v2 v2.5.2 | |
8 | 8 | github.com/spf13/cobra v0.0.5 |
9 | 9 | github.com/stretchr/testify v1.3.0 |
10 | 10 | golang.org/x/sync v0.0.0-20190423024810-112230192c58 |
13 | 13 | github.com/gobuffalo/logger v1.0.0/go.mod h1:2zbswyIUa45I+c+FLXuWl9zSWEiVuthsk8ze5s8JvPs= |
14 | 14 | github.com/gobuffalo/packd v0.3.0 h1:eMwymTkA1uXsqxS0Tpoop3Lc0u3kTfiMBE6nKtQU4g4= |
15 | 15 | github.com/gobuffalo/packd v0.3.0/go.mod h1:zC7QkmNkYVGKPw4tHpBQ+ml7W/3tIebgeo1b36chA3Q= |
16 | github.com/gobuffalo/packr/v2 v2.5.1 h1:TFOeY2VoGamPjQLiNDT3mn//ytzk236VMO2j7iHxJR4= | |
17 | github.com/gobuffalo/packr/v2 v2.5.1/go.mod h1:8f9c96ITobJlPzI44jj+4tHnEKNt0xXWSVlXRN9X1Iw= | |
16 | github.com/gobuffalo/packr/v2 v2.5.2 h1:4EvjeIpQLZuRIljwnidYgbRXbr1yIzVRrESiLjqKj6s= | |
17 | github.com/gobuffalo/packr/v2 v2.5.2/go.mod h1:sgEE1xNZ6G0FNN5xn9pevVu4nywaxHvgup67xisti08= | |
18 | 18 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= |
19 | 19 | github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= |
20 | 20 | github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= |
70 | 70 | golang.org/x/sys v0.0.0-20190515120540-06a5c4944438 h1:khxRGsvPk4n2y8I/mLLjp7e5dMTJmH75wvqS6nMwUtY= |
71 | 71 | golang.org/x/sys v0.0.0-20190515120540-06a5c4944438/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
72 | 72 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= |
73 | golang.org/x/tools v0.0.0-20190624180213-70d37148ca0c h1:KfpJVdWhuRqNk4XVXzjXf2KAV4TBEP77SYdFGjeGuIE= | |
74 | golang.org/x/tools v0.0.0-20190624180213-70d37148ca0c/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= | |
73 | golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0 h1:Dh6fw+p6FyRl5x/FvNswO1ji0lIGzm3KP8Y9VkS9PTE= | |
74 | golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= | |
75 | 75 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= |
76 | 76 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= |
77 | 77 | gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= |
10 | 10 | Use: "version", |
11 | 11 | Short: "prints packr version", |
12 | 12 | Run: func(cmd *cobra.Command, args []string) { |
13 | fmt.Print(packr.Version) | |
13 | fmt.Println(packr.Version) | |
14 | 14 | }, |
15 | 15 | } |
16 | 16 |
33 | 33 | - '^docs:' |
34 | 34 | - '^test:' |
35 | 35 | |
36 | brew: | |
37 | github: | |
38 | owner: gobuffalo | |
39 | name: homebrew-tap | |
36 | brews: | |
37 | - | |
38 | github: | |
39 | owner: gobuffalo | |
40 | name: homebrew-tap | |
40 | 41 |
30 | 30 | - '^docs:' |
31 | 31 | - '^test:' |
32 | 32 | <%= if (brew) { %> |
33 | brew: | |
34 | github: | |
35 | owner: gobuffalo | |
36 | name: homebrew-tap | |
33 | brews: | |
34 | - | |
35 | github: | |
36 | owner: gobuffalo | |
37 | name: homebrew-tap | |
37 | 38 | <% } %> |
13 | 13 | endif |
14 | 14 | |
15 | 15 | deps: |
16 | $(GO_BIN) get github.com/gobuffalo/release | |
17 | 16 | $(GO_BIN) get -tags ${TAGS} -t ./... |
18 | 17 | $(GO_BIN) install -v ./packr2 |
19 | 18 | make tidy |
0 | **NOTICE: Please consider migrating your projects to github.com/markbates/pkger. It has an idiomatic API, minimal dependencies, a stronger test suite (tested directly against the std lib counterparts), transparent tooling, and more.** | |
1 | ||
2 | https://blog.gobuffalo.io/introducing-pkger-static-file-embedding-in-go-1ce76dc79c65 | |
3 | ||
0 | 4 | # Packr (v2) |
1 | 5 | |
2 | 6 | [![GoDoc](https://godoc.org/github.com/gobuffalo/packr/v2?status.svg)](https://godoc.org/github.com/gobuffalo/packr/v2) |
0 | # github.com/gobuffalo/packr/v2 Stands on the Shoulders of Giants | |
0 | # /Users/smichalak/dev/packr/v2 Stands on the Shoulders of Giants | |
1 | 1 | |
2 | github.com/gobuffalo/packr/v2 does not try to reinvent the wheel! Instead, it uses the already great wheels developed by the Go community and puts them all together in the best way possible. Without these giants, this project would not be possible. Please make sure to check them out and thank them for all of their hard work. | |
2 | /Users/smichalak/dev/packr/v2 does not try to reinvent the wheel! Instead, it uses the already great wheels developed by the Go community and puts them all together in the best way possible. Without these giants, this project would not be possible. Please make sure to check them out and thank them for all of their hard work. | |
3 | 3 | |
4 | 4 | Thank you to the following **GIANTS**: |
5 | 5 | |
6 | ||
7 | * [github.com/gobuffalo/envy](https://godoc.org/github.com/gobuffalo/envy) | |
8 | 6 | |
9 | 7 | * [github.com/gobuffalo/logger](https://godoc.org/github.com/gobuffalo/logger) |
10 | 8 | |
11 | 9 | * [github.com/gobuffalo/packd](https://godoc.org/github.com/gobuffalo/packd) |
12 | 10 | |
13 | 11 | * [github.com/karrick/godirwalk](https://godoc.org/github.com/karrick/godirwalk) |
12 | ||
13 | * [github.com/konsorten/go-windows-terminal-sequences](https://godoc.org/github.com/konsorten/go-windows-terminal-sequences) | |
14 | ||
15 | * [github.com/markbates/errx](https://godoc.org/github.com/markbates/errx) | |
16 | ||
17 | * [github.com/markbates/oncer](https://godoc.org/github.com/markbates/oncer) | |
18 | ||
19 | * [github.com/markbates/safe](https://godoc.org/github.com/markbates/safe) | |
14 | 20 | |
15 | 21 | * [github.com/rogpeppe/go-internal](https://godoc.org/github.com/rogpeppe/go-internal) |
16 | 22 |
0 | Css |
0 | Footer |
0 | Index |
0 | Sub |
15 | 15 | "github.com/gobuffalo/packr/v2/file" |
16 | 16 | "github.com/gobuffalo/packr/v2/file/resolver" |
17 | 17 | "github.com/gobuffalo/packr/v2/plog" |
18 | "github.com/gobuffalo/packr/v2/internal/takeon/github.com/markbates/oncer" | |
18 | "github.com/markbates/oncer" | |
19 | 19 | ) |
20 | 20 | |
21 | 21 | var _ packd.Box = &Box{} |
27 | 27 | // Box represent a folder on a disk you want to |
28 | 28 | // have access to in the built Go binary. |
29 | 29 | type Box struct { |
30 | Path string `json:"path"` | |
31 | Name string `json:"name"` | |
32 | ResolutionDir string `json:"resolution_dir"` | |
33 | DefaultResolver resolver.Resolver `json:"default_resolver"` | |
34 | resolvers resolversMap | |
35 | dirs dirsMap | |
30 | Path string `json:"path"` | |
31 | Name string `json:"name"` | |
32 | ResolutionDir string `json:"resolution_dir"` | |
33 | DefaultResolver resolver.Resolver `json:"default_resolver"` | |
34 | resolvers resolversMap | |
35 | dirs dirsMap | |
36 | 36 | } |
37 | 37 | |
38 | 38 | // NewBox returns a Box that can be used to |
214 | 214 | |
215 | 215 | f, err := r.Resolve(b.Name, key) |
216 | 216 | if err != nil { |
217 | z := filepath.Join(resolver.OsPath(b.ResolutionDir), filepath.FromSlash(path.Clean("/"+resolver.OsPath(key)))) | |
217 | z, err := resolver.ResolvePathInBase(resolver.OsPath(b.ResolutionDir), filepath.FromSlash(path.Clean("/"+resolver.OsPath(key)))) | |
218 | if err != nil { | |
219 | plog.Debug(r, "Resolve", "box", b.Name, "key", key, "err", err) | |
220 | return f, err | |
221 | } | |
222 | ||
218 | 223 | f, err = r.Resolve(b.Name, z) |
219 | 224 | if err != nil { |
220 | 225 | plog.Debug(r, "Resolve", "box", b.Name, "key", z, "err", err) |
181 | 181 | r := require.New(t) |
182 | 182 | |
183 | 183 | d := resolver.NewInMemory(map[string]file.File{ |
184 | "foo.txt": qfile("foo.txt", "foo!"), | |
185 | "bar": qfile("bar", "bar!"), | |
186 | "baz/index.html": qfile("baz", "baz!"), | |
184 | "foo.txt": qfile("foo.txt", "foo!"), | |
185 | "bar": qfile("bar", "bar!"), | |
186 | "baz/index.html": qfile("baz", "baz!"), | |
187 | 187 | }) |
188 | 188 | box := New("Test_Box_Open", "./templates") |
189 | 189 | |
222 | 222 | r.True(box.HasDir("c")) |
223 | 223 | r.False(box.HasDir("a")) |
224 | 224 | } |
225 | ||
226 | func Test_Box_Traversal_Standard(t *testing.T) { | |
227 | r := require.New(t) | |
228 | box := New("Test_Box_Traversal_Standard", "") | |
229 | _, err := box.FindString("../fixtures/hello.txt") | |
230 | r.Error(err) | |
231 | } | |
232 | ||
233 | func Test_Box_Traversal_Standard_Depth2(t *testing.T) { | |
234 | r := require.New(t) | |
235 | box := New("Test_Box_Traversal_Standard_Depth2", "") | |
236 | _, err := box.FindString("../../packr/fixtures/hello.txt") | |
237 | r.Error(err) | |
238 | } | |
239 | ||
240 | func Test_Box_Traversal_Backslash(t *testing.T) { | |
241 | r := require.New(t) | |
242 | box := New("Test_Box_Traversal_Backslash", "") | |
243 | _, err := box.FindString("..\\fixtures\\hello.txt") | |
244 | r.Error(err) | |
245 | } | |
246 | ||
247 | func Test_Box_Traversal_Backslash_Depth2(t *testing.T) { | |
248 | r := require.New(t) | |
249 | box := New("Test_Box_Traversal_Backslash_Depth2", "") | |
250 | _, err := box.FindString("..\\..\\packr2\\fixtures\\hello.txt") | |
251 | r.Error(err) | |
252 | } |
5 | 5 | |
6 | 6 | "github.com/gobuffalo/packr/v2/file" |
7 | 7 | "github.com/gobuffalo/packr/v2/file/resolver" |
8 | "github.com/gobuffalo/packr/v2/internal/takeon/github.com/markbates/oncer" | |
8 | "github.com/markbates/oncer" | |
9 | 9 | ) |
10 | 10 | |
11 | 11 | // File has been deprecated and file.File should be used instead |
5 | 5 | ) |
6 | 6 | |
7 | 7 | type info struct { |
8 | Path string | |
9 | Contents []byte | |
10 | size int64 | |
11 | modTime time.Time | |
12 | isDir bool | |
8 | Path string | |
9 | Contents []byte | |
10 | size int64 | |
11 | modTime time.Time | |
12 | isDir bool | |
13 | 13 | } |
14 | 14 | |
15 | 15 | func (f info) Name() string { |
22 | 22 | } |
23 | 23 | |
24 | 24 | func (d *Disk) Resolve(box string, name string) (file.File, error) { |
25 | var err error | |
25 | 26 | path := OsPath(name) |
26 | 27 | if !filepath.IsAbs(path) { |
27 | path = filepath.Join(OsPath(d.Root), path) | |
28 | path, err = ResolvePathInBase(OsPath(d.Root), path) | |
29 | if err != nil { | |
30 | return nil, err | |
31 | } | |
28 | 32 | } |
33 | ||
29 | 34 | fi, err := os.Stat(path) |
30 | 35 | if err != nil { |
31 | 36 | return nil, err |
32 | 37 | } |
33 | 38 | if fi.IsDir() { |
34 | return file.NewDir(OsPath(name)) | |
39 | return nil, os.ErrNotExist | |
35 | 40 | } |
36 | 41 | if bb, err := ioutil.ReadFile(path); err == nil { |
37 | 42 | return file.NewFile(OsPath(name), bb) |
38 | 43 | } |
39 | 44 | return nil, os.ErrNotExist |
45 | } | |
46 | ||
47 | // ResolvePathInBase returns a path that is guaranteed to be inside of the base directory or an error | |
48 | func ResolvePathInBase(base, path string) (string, error) { | |
49 | // Determine the absolute file path of the base directory | |
50 | d, err := filepath.Abs(base) | |
51 | if err != nil { | |
52 | return "", err | |
53 | } | |
54 | ||
55 | // Return the base directory if no file was requested | |
56 | if path == "/" || path == "\\" { | |
57 | return d, nil | |
58 | } | |
59 | ||
60 | // Resolve the absolute file path after combining the key with base | |
61 | p, err := filepath.Abs(filepath.Join(d, path)) | |
62 | if err != nil { | |
63 | return "", err | |
64 | } | |
65 | ||
66 | // Verify that the resolved path is inside of the base directory | |
67 | if !strings.HasPrefix(p, d+string(filepath.Separator)) { | |
68 | return "", os.ErrNotExist | |
69 | } | |
70 | return p, nil | |
40 | 71 | } |
41 | 72 | |
42 | 73 | var _ file.FileMappable = &Disk{} |
69 | 100 | return nil |
70 | 101 | } |
71 | 102 | err := godirwalk.Walk(root, &godirwalk.Options{ |
72 | FollowSymbolicLinks: true, | |
73 | Callback: callback, | |
103 | FollowSymbolicLinks: true, | |
104 | Callback: callback, | |
74 | 105 | }) |
75 | 106 | if err != nil { |
76 | 107 | plog.Logger.Errorf("[%s] error walking %v", root, err) |
14 | 14 | |
15 | 15 | // EncodedLen returns the length of an encoding of n source bytes. |
16 | 16 | // Specifically, it returns n * 2. |
17 | func EncodedLen(n int) int { return n * 2 } | |
17 | func EncodedLen(n int) int { return n * 2 } | |
18 | 18 | |
19 | 19 | // Encode encodes src into EncodedLen(len(src)) |
20 | 20 | // bytes of dst. As a convenience, it returns the number |
43 | 43 | |
44 | 44 | // DecodedLen returns the length of a decoding of x source bytes. |
45 | 45 | // Specifically, it returns x / 2. |
46 | func DecodedLen(x int) int { return x / 2 } | |
46 | func DecodedLen(x int) int { return x / 2 } | |
47 | 47 | |
48 | 48 | // Decode decodes src into DecodedLen(len(src)) bytes, |
49 | 49 | // returning the actual number of bytes written to dst. |
125 | 125 | const bufferSize = 1024 |
126 | 126 | |
127 | 127 | type encoder struct { |
128 | w io.Writer | |
129 | err error | |
130 | out [bufferSize]byte // output buffer | |
128 | w io.Writer | |
129 | err error | |
130 | out [bufferSize]byte // output buffer | |
131 | 131 | } |
132 | 132 | |
133 | 133 | // NewEncoder returns an io.Writer that writes lowercase hexadecimal characters to w. |
152 | 152 | } |
153 | 153 | |
154 | 154 | type decoder struct { |
155 | r io.Reader | |
156 | err error | |
157 | in []byte // input buffer (encoded form) | |
158 | arr [bufferSize]byte // backing array for in | |
155 | r io.Reader | |
156 | err error | |
157 | in []byte // input buffer (encoded form) | |
158 | arr [bufferSize]byte // backing array for in | |
159 | 159 | } |
160 | 160 | |
161 | 161 | // NewDecoder returns an io.Reader that decodes hexadecimal characters from r. |
168 | 168 | // Fill internal buffer with sufficient bytes to decode |
169 | 169 | if len(d.in) < 2 && d.err == nil { |
170 | 170 | var numCopy, numRead int |
171 | numCopy = copy(d.arr[:], d.in) // Copies either 0 or 1 bytes | |
171 | numCopy = copy(d.arr[:], d.in) // Copies either 0 or 1 bytes | |
172 | 172 | numRead, d.err = d.r.Read(d.arr[numCopy:]) |
173 | 173 | d.in = d.arr[:numCopy+numRead] |
174 | 174 | if d.err == io.EOF && len(d.in)%2 != 0 { |
187 | 187 | numDec, err := Decode(p, d.in[:len(p)*2]) |
188 | 188 | d.in = d.in[2*numDec:] |
189 | 189 | if err != nil { |
190 | d.in, d.err = nil, err // Decode error; discard input remainder | |
190 | d.in, d.err = nil, err // Decode error; discard input remainder | |
191 | 191 | } |
192 | 192 | |
193 | 193 | if len(d.in) < 2 { |
194 | return numDec, d.err // Only expose errors when buffer fully consumed | |
194 | return numDec, d.err // Only expose errors when buffer fully consumed | |
195 | 195 | } |
196 | 196 | return numDec, nil |
197 | 197 | } |
204 | 204 | } |
205 | 205 | |
206 | 206 | type dumper struct { |
207 | w io.Writer | |
208 | rightChars [18]byte | |
209 | buf [14]byte | |
210 | used int // number of bytes in the current line | |
211 | n uint // number of bytes, total | |
212 | closed bool | |
207 | w io.Writer | |
208 | rightChars [18]byte | |
209 | buf [14]byte | |
210 | used int // number of bytes in the current line | |
211 | n uint // number of bytes, total | |
212 | closed bool | |
213 | 213 | } |
214 | 214 | |
215 | 215 | func toChar(b byte) byte { |
17 | 17 | var _ Resolver = &HexGzip{} |
18 | 18 | |
19 | 19 | type HexGzip struct { |
20 | packed map[string]string | |
21 | unpacked map[string]string | |
22 | moot *sync.RWMutex | |
20 | packed map[string]string | |
21 | unpacked map[string]string | |
22 | moot *sync.RWMutex | |
23 | 23 | } |
24 | 24 | |
25 | 25 | func (hg HexGzip) String() string { |
76 | 76 | } |
77 | 77 | |
78 | 78 | hg := &HexGzip{ |
79 | packed: files, | |
80 | unpacked: map[string]string{}, | |
81 | moot: &sync.RWMutex{}, | |
79 | packed: files, | |
80 | unpacked: map[string]string{}, | |
81 | moot: &sync.RWMutex{}, | |
82 | 82 | } |
83 | 83 | |
84 | 84 | return hg, nil |
8 | 8 | |
9 | 9 | func Test_Ident_OsPath(t *testing.T) { |
10 | 10 | table := map[string]string{ |
11 | "foo/bar/baz": "foo/bar/baz", | |
12 | "foo\\bar\\baz": "foo/bar/baz", | |
11 | "foo/bar/baz": "foo/bar/baz", | |
12 | "foo\\bar\\baz": "foo/bar/baz", | |
13 | 13 | } |
14 | 14 | |
15 | 15 | if runtime.GOOS == "windows" { |
26 | 26 | |
27 | 27 | func ident_OsPath_Windows_Table() map[string]string { |
28 | 28 | return map[string]string{ |
29 | "foo/bar/baz": "foo\\bar\\baz", | |
30 | "foo\\bar\\baz": "foo\\bar\\baz", | |
29 | "foo/bar/baz": "foo\\bar\\baz", | |
30 | "foo\\bar\\baz": "foo\\bar\\baz", | |
31 | 31 | } |
32 | 32 | } |
0 | 0 | module github.com/gobuffalo/packr/v2 |
1 | 1 | |
2 | go 1.12 | |
2 | go 1.13 | |
3 | 3 | |
4 | 4 | require ( |
5 | github.com/gobuffalo/envy v1.7.0 | |
6 | github.com/gobuffalo/logger v1.0.0 | |
7 | github.com/gobuffalo/packd v0.3.0 | |
8 | github.com/karrick/godirwalk v1.10.12 | |
9 | github.com/rogpeppe/go-internal v1.3.0 | |
5 | github.com/gobuffalo/logger v1.0.3 | |
6 | github.com/gobuffalo/packd v1.0.0 | |
7 | github.com/karrick/godirwalk v1.15.8 | |
8 | github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect | |
9 | github.com/markbates/errx v1.1.0 | |
10 | github.com/markbates/oncer v1.0.0 | |
11 | github.com/markbates/safe v1.0.1 | |
12 | github.com/rogpeppe/go-internal v1.5.2 | |
10 | 13 | github.com/sirupsen/logrus v1.4.2 |
11 | github.com/spf13/cobra v0.0.5 | |
12 | github.com/stretchr/testify v1.3.0 | |
13 | golang.org/x/sync v0.0.0-20190423024810-112230192c58 | |
14 | golang.org/x/tools v0.0.0-20190624180213-70d37148ca0c | |
14 | github.com/spf13/cobra v0.0.6 | |
15 | github.com/stretchr/testify v1.5.1 | |
16 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e | |
17 | golang.org/x/tools v0.0.0-20200308013534-11ec41452d41 | |
15 | 18 | ) |
0 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= | |
0 | 1 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= |
2 | github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= | |
3 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= | |
4 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= | |
1 | 5 | github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= |
6 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= | |
7 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= | |
8 | github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= | |
9 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= | |
10 | github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= | |
2 | 11 | github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= |
3 | github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= | |
4 | 12 | github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= |
5 | github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= | |
13 | github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= | |
14 | github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= | |
15 | github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= | |
6 | 16 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
7 | 17 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= |
8 | 18 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
19 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= | |
20 | github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= | |
9 | 21 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= |
10 | github.com/gobuffalo/envy v1.7.0 h1:GlXgaiBkmrYMHco6t4j7SacKO4XUjvh5pwXh0f4uxXU= | |
11 | github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= | |
12 | github.com/gobuffalo/logger v1.0.0 h1:xw9Ko9EcC5iAFprrjJ6oZco9UpzS5MQ4jAwghsLHdy4= | |
13 | github.com/gobuffalo/logger v1.0.0/go.mod h1:2zbswyIUa45I+c+FLXuWl9zSWEiVuthsk8ze5s8JvPs= | |
14 | github.com/gobuffalo/packd v0.3.0 h1:eMwymTkA1uXsqxS0Tpoop3Lc0u3kTfiMBE6nKtQU4g4= | |
15 | github.com/gobuffalo/packd v0.3.0/go.mod h1:zC7QkmNkYVGKPw4tHpBQ+ml7W/3tIebgeo1b36chA3Q= | |
22 | github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= | |
23 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= | |
24 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= | |
25 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= | |
26 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= | |
27 | github.com/gobuffalo/logger v1.0.3 h1:YaXOTHNPCvkqqA7w05A4v0k2tCdpr+sgFlgINbQ6gqc= | |
28 | github.com/gobuffalo/logger v1.0.3/go.mod h1:SoeejUwldiS7ZsyCBphOGURmWdwUFXs0J7TCjEhjKxM= | |
29 | github.com/gobuffalo/packd v1.0.0 h1:6ERZvJHfe24rfFmA9OaoKBdC7+c9sydrytMg8SdFGBM= | |
30 | github.com/gobuffalo/packd v1.0.0/go.mod h1:6VTc4htmJRFB7u1m/4LeMTWjFoYrUiBkU9Fdec9hrhI= | |
31 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= | |
32 | github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= | |
33 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= | |
34 | github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= | |
35 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= | |
36 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= | |
37 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= | |
38 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= | |
39 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= | |
40 | github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= | |
41 | github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= | |
42 | github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= | |
43 | github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= | |
16 | 44 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= |
17 | 45 | github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= |
18 | 46 | github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= |
19 | github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= | |
20 | github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= | |
21 | github.com/karrick/godirwalk v1.10.12 h1:BqUm+LuJcXjGv1d2mj3gBiQyrQ57a0rYoAmhvJQ7RDU= | |
22 | github.com/karrick/godirwalk v1.10.12/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= | |
47 | github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= | |
48 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= | |
49 | github.com/karrick/godirwalk v1.15.8 h1:7+rWAZPn9zuRxaIqqT8Ohs2Q2Ac0msBqwRdxNCr2VVs= | |
50 | github.com/karrick/godirwalk v1.15.8/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk= | |
51 | github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= | |
52 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= | |
53 | github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= | |
23 | 54 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= |
24 | 55 | github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= |
25 | 56 | github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= |
57 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= | |
58 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= | |
26 | 59 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= |
27 | 60 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= |
61 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= | |
28 | 62 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= |
29 | 63 | github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= |
64 | github.com/markbates/errx v1.1.0 h1:QDFeR+UP95dO12JgW+tgi2UVfo0V8YBHiUIOaeBPiEI= | |
65 | github.com/markbates/errx v1.1.0/go.mod h1:PLa46Oex9KNbVDZhKel8v1OT7hD5JZ2eI7AHhA0wswc= | |
66 | github.com/markbates/oncer v1.0.0 h1:E83IaVAHygyndzPimgUYJjbshhDTALZyXxvk9FOlQRY= | |
67 | github.com/markbates/oncer v1.0.0/go.mod h1:Z59JA581E9GP6w96jai+TGqafHPW+cPfRxz2aSZ0mcI= | |
68 | github.com/markbates/safe v1.0.1 h1:yjZkbvRM6IzKj9tlu/zMJLS0n/V351OZWRnF3QfaUxI= | |
69 | github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= | |
70 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= | |
30 | 71 | github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= |
31 | 72 | github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= |
73 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= | |
74 | github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= | |
32 | 75 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= |
76 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | |
33 | 77 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= |
34 | 78 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= |
35 | github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= | |
36 | github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk= | |
37 | github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= | |
38 | github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= | |
79 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= | |
80 | github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= | |
81 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= | |
82 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= | |
83 | github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= | |
84 | github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= | |
85 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= | |
86 | github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= | |
87 | github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= | |
88 | github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= | |
89 | github.com/rogpeppe/go-internal v1.5.2 h1:qLvObTrvO/XRCqmkKxUlOBc48bI3efyDuAZe25QiF0w= | |
90 | github.com/rogpeppe/go-internal v1.5.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= | |
91 | github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | |
92 | github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= | |
93 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= | |
39 | 94 | github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= |
40 | 95 | github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= |
96 | github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= | |
97 | github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= | |
41 | 98 | github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= |
42 | 99 | github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= |
43 | github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s= | |
44 | github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= | |
100 | github.com/spf13/cobra v0.0.6 h1:breEStsVwemnKh2/s6gMvSdMEkwW0sK8vGStnlVBMCs= | |
101 | github.com/spf13/cobra v0.0.6/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= | |
45 | 102 | github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= |
46 | 103 | github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= |
47 | 104 | github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= |
48 | github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= | |
105 | github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= | |
49 | 106 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= |
50 | 107 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= |
51 | 108 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= |
52 | github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= | |
53 | 109 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= |
54 | github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= | |
110 | github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= | |
111 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= | |
112 | github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= | |
113 | github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= | |
114 | github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= | |
115 | github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= | |
116 | github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= | |
55 | 117 | github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= |
56 | golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= | |
118 | go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= | |
119 | go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= | |
120 | go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= | |
121 | go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= | |
122 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= | |
57 | 123 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= |
58 | golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 h1:ydJNl0ENAG67pFbB+9tfhiL2pYqLhfoaZFw/cjLhY4A= | |
59 | golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= | |
124 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= | |
125 | golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c h1:/nJuwDLoL/zrqY6gf57vxC+Pi+pZ8bfhpPkicO5H7W4= | |
126 | golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= | |
127 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= | |
128 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= | |
129 | golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= | |
130 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | |
131 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | |
132 | golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | |
60 | 133 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= |
61 | 134 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= |
62 | golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= | |
135 | golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= | |
136 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= | |
137 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= | |
138 | golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= | |
139 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= | |
140 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | |
141 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | |
142 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | |
63 | 143 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= |
64 | golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | |
144 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= | |
145 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | |
146 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | |
147 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | |
148 | golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | |
149 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | |
65 | 150 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= |
66 | 151 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
152 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= | |
67 | 153 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
68 | golang.org/x/sys v0.0.0-20190515120540-06a5c4944438 h1:khxRGsvPk4n2y8I/mLLjp7e5dMTJmH75wvqS6nMwUtY= | |
69 | golang.org/x/sys v0.0.0-20190515120540-06a5c4944438/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | |
70 | 154 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= |
71 | golang.org/x/tools v0.0.0-20190624180213-70d37148ca0c h1:KfpJVdWhuRqNk4XVXzjXf2KAV4TBEP77SYdFGjeGuIE= | |
72 | golang.org/x/tools v0.0.0-20190624180213-70d37148ca0c/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= | |
155 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= | |
156 | golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | |
157 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | |
158 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= | |
159 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | |
160 | golang.org/x/tools v0.0.0-20200308013534-11ec41452d41 h1:9Di9iYgOt9ThCipBxChBVhgNipDoE5mxO84rQV7D0FE= | |
161 | golang.org/x/tools v0.0.0-20200308013534-11ec41452d41/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= | |
162 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | |
163 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | |
164 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | |
165 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= | |
166 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= | |
167 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= | |
168 | google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= | |
169 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= | |
73 | 170 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= |
171 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= | |
74 | 172 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= |
75 | 173 | gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= |
174 | gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= | |
175 | gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= | |
176 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | |
177 | gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= | |
76 | 178 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
179 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= |
5 | 5 | "runtime" |
6 | 6 | "strings" |
7 | 7 | |
8 | "github.com/gobuffalo/envy" | |
9 | 8 | "github.com/gobuffalo/packr/v2/plog" |
10 | 9 | ) |
11 | 10 | |
12 | 11 | func construct(name string, path string) *Box { |
13 | 12 | return &Box{ |
14 | Path: path, | |
15 | Name: name, | |
16 | ResolutionDir: resolutionDir(path), | |
17 | resolvers: resolversMap{}, | |
18 | dirs: dirsMap{}, | |
13 | Path: path, | |
14 | Name: name, | |
15 | ResolutionDir: resolutionDir(path), | |
16 | resolvers: resolversMap{}, | |
17 | dirs: dirsMap{}, | |
19 | 18 | } |
20 | 19 | } |
21 | 20 | |
30 | 29 | return ng, true |
31 | 30 | } |
32 | 31 | |
33 | ng = filepath.Join(envy.GoPath(), "src", ng) | |
32 | ng = filepath.Join(os.Getenv("GOPATH"), "src", ng) | |
34 | 33 | if resolutionDirExists(ng, og) { |
35 | 34 | return ng, true |
36 | 35 | } |
24 | 24 | } |
25 | 25 | |
26 | 26 | hg, err := resolver.NewHexGzip(map[string]string{ |
27 | "index.html": ind, | |
28 | "hello.txt": hello, | |
27 | "index.html": ind, | |
28 | "hello.txt": hello, | |
29 | 29 | }) |
30 | 30 | if err != nil { |
31 | 31 | panic(err) |
128 | 128 | }) |
129 | 129 | } |
130 | 130 | } |
131 | ||
132 | func Test_HTTPBox_Disk(t *testing.T) { | |
133 | r := require.New(t) | |
134 | ||
135 | box := New("http disk box", "./_fixtures/http_test") | |
136 | mux := http.NewServeMux() | |
137 | mux.Handle("/", http.FileServer(box)) | |
138 | ||
139 | type testcase struct { | |
140 | URL, Content, Location string | |
141 | Code int | |
142 | } | |
143 | ||
144 | testcases := []testcase{ | |
145 | {"/", "Index", "", 200}, | |
146 | {"/sub", "Sub", "", 200}, | |
147 | {"/index.html", "", "./", 301}, | |
148 | {"/sub/index.html", "", "./", 301}, | |
149 | {"/sub/", "", "../sub", 301}, | |
150 | {"/footer.html", "Footer", "", 200}, | |
151 | {"/css/main.css", "Css", "", 200}, | |
152 | {"/css", "404 page not found", "", 404}, | |
153 | {"/css/", "404 page not found", "", 404}, | |
154 | } | |
155 | ||
156 | for _, tc := range testcases { | |
157 | t.Run("path"+tc.URL, func(t *testing.T) { | |
158 | req, err := http.NewRequest("GET", tc.URL, nil) | |
159 | r.NoError(err) | |
160 | res := httptest.NewRecorder() | |
161 | mux.ServeHTTP(res, req) | |
162 | ||
163 | r.Equal(tc.Code, res.Code) | |
164 | r.Equal(tc.Location, res.Header().Get("location")) | |
165 | r.Equal(tc.Content, strings.TrimSpace(res.Body.String())) | |
166 | }) | |
167 | } | |
168 | } |
0 | package internal | |
1 | ||
2 | import ( | |
3 | "os" | |
4 | "runtime" | |
5 | "strings" | |
6 | ) | |
7 | ||
8 | // Mods returns true when go modules supports is enabled | |
9 | func Mods() bool { | |
10 | go111 := os.Getenv("GO111MODULE") | |
11 | ||
12 | if !inGoPath() { | |
13 | return go111 != "off" | |
14 | } | |
15 | ||
16 | return go111 == "on" | |
17 | } | |
18 | ||
19 | func inGoPath() bool { | |
20 | pwd, _ := os.Getwd() | |
21 | for _, p := range GoPaths() { | |
22 | if strings.HasPrefix(pwd, p) { | |
23 | return true | |
24 | } | |
25 | } | |
26 | return false | |
27 | } | |
28 | ||
29 | // GoPaths return the defined gopath list. | |
30 | func GoPaths() []string { | |
31 | gp := os.Getenv("GOPATH") | |
32 | if runtime.GOOS == "windows" { | |
33 | return strings.Split(gp, ";") // Windows uses a different separator | |
34 | } | |
35 | return strings.Split(gp, ":") | |
36 | } |
0 | *.log | |
1 | .DS_Store | |
2 | doc | |
3 | tmp | |
4 | pkg | |
5 | *.gem | |
6 | *.pid | |
7 | coverage | |
8 | coverage.data | |
9 | build/* | |
10 | *.pbxuser | |
11 | *.mode1v3 | |
12 | .svn | |
13 | profile | |
14 | .console_history | |
15 | .sass-cache/* | |
16 | .rake_tasks~ | |
17 | *.log.lck | |
18 | solr/ | |
19 | .jhw-cache/ | |
20 | jhw.* | |
21 | *.sublime* | |
22 | node_modules/ | |
23 | dist/ | |
24 | generated/ | |
25 | .vendor/ | |
26 | bin/* | |
27 | gin-bin | |
28 | .idea/ |
0 | The MIT License (MIT) | |
1 | ||
2 | Copyright (c) 2019 Mark Bates | |
3 | ||
4 | Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | of this software and associated documentation files (the "Software"), to deal | |
6 | in the Software without restriction, including without limitation the rights | |
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | copies of the Software, and to permit persons to whom the Software is | |
9 | furnished to do so, subject to the following conditions: | |
10 | ||
11 | The above copyright notice and this permission notice shall be included in all | |
12 | copies or substantial portions of the Software. | |
13 | ||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
20 | SOFTWARE. |
0 | TAGS ?= "" | |
1 | GO_BIN ?= "go" | |
2 | ||
3 | install: | |
4 | $(GO_BIN) install -tags ${TAGS} -v . | |
5 | make tidy | |
6 | ||
7 | tidy: | |
8 | ifeq ($(GO111MODULE),on) | |
9 | $(GO_BIN) mod tidy | |
10 | else | |
11 | echo skipping go mod tidy | |
12 | endif | |
13 | ||
14 | deps: | |
15 | $(GO_BIN) get -tags ${TAGS} -t ./... | |
16 | make tidy | |
17 | ||
18 | build: | |
19 | $(GO_BIN) build -v . | |
20 | make tidy | |
21 | ||
22 | test: | |
23 | $(GO_BIN) test -cover -tags ${TAGS} ./... | |
24 | make tidy | |
25 | ||
26 | ci-deps: | |
27 | $(GO_BIN) get -tags ${TAGS} -t ./... | |
28 | ||
29 | ci-test: | |
30 | $(GO_BIN) test -tags ${TAGS} -race ./... | |
31 | ||
32 | lint: | |
33 | go get github.com/golangci/golangci-lint/cmd/golangci-lint | |
34 | golangci-lint run --enable-all | |
35 | make tidy | |
36 | ||
37 | update: | |
38 | ifeq ($(GO111MODULE),on) | |
39 | rm go.* | |
40 | $(GO_BIN) mod init | |
41 | $(GO_BIN) mod tidy | |
42 | else | |
43 | $(GO_BIN) get -u -tags ${TAGS} | |
44 | endif | |
45 | make test | |
46 | make install | |
47 | make tidy | |
48 | ||
49 | release-test: | |
50 | $(GO_BIN) test -tags ${TAGS} -race ./... | |
51 | make tidy | |
52 | ||
53 | release: | |
54 | $(GO_BIN) get github.com/gobuffalo/release | |
55 | make tidy | |
56 | release -y -f version.go --skip-packr | |
57 | make tidy | |
58 | ||
59 | ||
60 |
0 | # github.com/markbates/errx Stands on the Shoulders of Giants | |
1 | ||
2 | github.com/markbates/errx does not try to reinvent the wheel! Instead, it uses the already great wheels developed by the Go community and puts them all together in the best way possible. Without these giants, this project would not be possible. Please make sure to check them out and thank them for all of their hard work. | |
3 | ||
4 | Thank you to the following **GIANTS**: | |
5 |
0 | variables: | |
1 | GOBIN: "$(GOPATH)/bin" # Go binaries path | |
2 | GOPATH: "$(system.defaultWorkingDirectory)/gopath" # Go workspace path | |
3 | modulePath: "$(GOPATH)/src/github.com/$(build.repository.name)" # Path to the module"s code | |
4 | ||
5 | jobs: | |
6 | - job: Windows | |
7 | pool: | |
8 | vmImage: "vs2017-win2016" | |
9 | strategy: | |
10 | matrix: | |
11 | go 1.10: | |
12 | go_version: "1.10" | |
13 | go 1.11 (on): | |
14 | go_version: "1.11.5" | |
15 | GO111MODULE: "on" | |
16 | go 1.11 (off): | |
17 | go_version: "1.11.5" | |
18 | GO111MODULE: "off" | |
19 | go 1.12 (on): | |
20 | go_version: "1.12" | |
21 | GO111MODULE: "on" | |
22 | go 1.12 (off): | |
23 | go_version: "1.12" | |
24 | GO111MODULE: "off" | |
25 | steps: | |
26 | - template: azure-tests.yml | |
27 | ||
28 | - job: macOS | |
29 | pool: | |
30 | vmImage: "macOS-10.13" | |
31 | strategy: | |
32 | matrix: | |
33 | go 1.10: | |
34 | go_version: "1.10" | |
35 | go 1.11 (on): | |
36 | go_version: "1.11.5" | |
37 | GO111MODULE: "on" | |
38 | go 1.11 (off): | |
39 | go_version: "1.11.5" | |
40 | GO111MODULE: "off" | |
41 | go 1.12 (on): | |
42 | go_version: "1.12" | |
43 | GO111MODULE: "on" | |
44 | go 1.12 (off): | |
45 | go_version: "1.12" | |
46 | GO111MODULE: "off" | |
47 | steps: | |
48 | - template: azure-tests.yml | |
49 | ||
50 | - job: Linux | |
51 | pool: | |
52 | vmImage: "ubuntu-16.04" | |
53 | strategy: | |
54 | matrix: | |
55 | go 1.10: | |
56 | go_version: "1.10" | |
57 | go 1.11 (on): | |
58 | go_version: "1.11.5" | |
59 | GO111MODULE: "on" | |
60 | go 1.11 (off): | |
61 | go_version: "1.11.5" | |
62 | GO111MODULE: "off" | |
63 | go 1.12 (on): | |
64 | go_version: "1.12" | |
65 | GO111MODULE: "on" | |
66 | go 1.12 (off): | |
67 | go_version: "1.12" | |
68 | GO111MODULE: "off" | |
69 | steps: | |
70 | - template: azure-tests.yml |
0 | steps: | |
1 | - task: GoTool@0 | |
2 | inputs: | |
3 | version: $(go_version) | |
4 | - task: Bash@3 | |
5 | inputs: | |
6 | targetType: inline | |
7 | script: | | |
8 | mkdir -p "$(GOBIN)" | |
9 | mkdir -p "$(GOPATH)/pkg" | |
10 | mkdir -p "$(modulePath)" | |
11 | shopt -s extglob | |
12 | mv !(gopath) "$(modulePath)" | |
13 | displayName: "Setup Go Workspace" | |
14 | - script: | | |
15 | go get -t -v ./... | |
16 | go test -race ./... | |
17 | workingDirectory: "$(modulePath)" | |
18 | displayName: "Tests" |
0 | package errx | |
1 | ||
2 | // go2 errors | |
3 | type Wrapper interface { | |
4 | Unwrap() error | |
5 | } | |
6 | ||
7 | // pkg/errors | |
8 | type Causer interface { | |
9 | Cause() error | |
10 | } | |
11 | ||
12 | func Unwrap(err error) error { | |
13 | switch e := err.(type) { | |
14 | case Wrapper: | |
15 | return e.Unwrap() | |
16 | case Causer: | |
17 | return e.Cause() | |
18 | } | |
19 | return err | |
20 | } | |
21 | ||
22 | var Cause = Unwrap |
0 | *.log | |
1 | .DS_Store | |
2 | doc | |
3 | tmp | |
4 | pkg | |
5 | *.gem | |
6 | *.pid | |
7 | coverage | |
8 | coverage.data | |
9 | build/* | |
10 | *.pbxuser | |
11 | *.mode1v3 | |
12 | .svn | |
13 | profile | |
14 | .console_history | |
15 | .sass-cache/* | |
16 | .rake_tasks~ | |
17 | *.log.lck | |
18 | solr/ | |
19 | .jhw-cache/ | |
20 | jhw.* | |
21 | *.sublime* | |
22 | node_modules/ | |
23 | dist/ | |
24 | generated/ | |
25 | .vendor/ | |
26 | bin/* | |
27 | gin-bin | |
28 | .idea/ |
0 | The MIT License (MIT) | |
1 | ||
2 | Copyright (c) 2018 Mark Bates | |
3 | ||
4 | Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | of this software and associated documentation files (the "Software"), to deal | |
6 | in the Software without restriction, including without limitation the rights | |
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | copies of the Software, and to permit persons to whom the Software is | |
9 | furnished to do so, subject to the following conditions: | |
10 | ||
11 | The above copyright notice and this permission notice shall be included in all | |
12 | copies or substantial portions of the Software. | |
13 | ||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
20 | SOFTWARE. |
0 | TAGS ?= "sqlite" | |
1 | GO_BIN ?= go | |
2 | ||
3 | install: | |
4 | packr | |
5 | $(GO_BIN) install -v . | |
6 | ||
7 | deps: | |
8 | $(GO_BIN) get github.com/gobuffalo/release | |
9 | $(GO_BIN) get github.com/gobuffalo/packr/packr | |
10 | $(GO_BIN) get -tags ${TAGS} -t ./... | |
11 | $(GO_BIN) mod tidy | |
12 | ||
13 | build: | |
14 | packr | |
15 | $(GO_BIN) build -v . | |
16 | ||
17 | test: | |
18 | packr | |
19 | $(GO_BIN) test -tags ${TAGS} ./... | |
20 | ||
21 | ci-test: deps | |
22 | $(GO_BIN) test -tags ${TAGS} -race ./... | |
23 | ||
24 | lint: | |
25 | gometalinter --vendor ./... --deadline=1m --skip=internal | |
26 | ||
27 | update: | |
28 | $(GO_BIN) get -u -tags ${TAGS} | |
29 | $(GO_BIN) mod tidy | |
30 | packr | |
31 | make test | |
32 | make install | |
33 | $(GO_BIN) mod tidy | |
34 | ||
35 | release-test: | |
36 | $(GO_BIN) test -tags ${TAGS} -race ./... | |
37 | ||
38 | release: | |
39 | release -y -f version.go |
0 | package oncer | |
1 | ||
2 | import ( | |
3 | "fmt" | |
4 | "io" | |
5 | "os" | |
6 | ) | |
7 | ||
8 | const deprecated = "DEPRECATED" | |
9 | ||
10 | var deprecationWriter io.Writer = os.Stdout | |
11 | ||
12 | func Deprecate(depth int, name string, msg string) { | |
13 | Do(deprecated+name, func() { | |
14 | fmt.Fprintf(deprecationWriter, "[%s] %s has been deprecated.\n", deprecated, name) | |
15 | if len(msg) > 0 { | |
16 | fmt.Fprintf(deprecationWriter, "\t%s\n", msg) | |
17 | } | |
18 | }) | |
19 | } |
0 | //+build debug | |
1 | ||
2 | package oncer | |
3 | ||
4 | import ( | |
5 | "fmt" | |
6 | "time" | |
7 | ) | |
8 | ||
9 | func log(name string, fn func()) func() { | |
10 | return func() { | |
11 | start := time.Now() | |
12 | if len(name) > 80 { | |
13 | name = name[(len(name) - 80):] | |
14 | } | |
15 | defer fmt.Println(name, time.Now().Sub(start)) | |
16 | fn() | |
17 | } | |
18 | } |
0 | package oncer | |
1 | ||
2 | import ( | |
3 | "sync" | |
4 | ) | |
5 | ||
6 | var onces = &sync.Map{} | |
7 | ||
8 | func Do(name string, fn func()) { | |
9 | o, _ := onces.LoadOrStore(name, &sync.Once{}) | |
10 | if once, ok := o.(*sync.Once); ok { | |
11 | once.Do(log(name, fn)) | |
12 | } | |
13 | } | |
14 | ||
15 | func Reset(names ...string) { | |
16 | if len(names) == 0 { | |
17 | onces = &sync.Map{} | |
18 | return | |
19 | } | |
20 | ||
21 | for _, n := range names { | |
22 | onces.Delete(n) | |
23 | onces.Delete(deprecated + n) | |
24 | } | |
25 | } |
0 | *.log | |
1 | .DS_Store | |
2 | doc | |
3 | tmp | |
4 | pkg | |
5 | *.gem | |
6 | *.pid | |
7 | coverage | |
8 | coverage.data | |
9 | build/* | |
10 | *.pbxuser | |
11 | *.mode1v3 | |
12 | .svn | |
13 | profile | |
14 | .console_history | |
15 | .sass-cache/* | |
16 | .rake_tasks~ | |
17 | *.log.lck | |
18 | solr/ | |
19 | .jhw-cache/ | |
20 | jhw.* | |
21 | *.sublime* | |
22 | node_modules/ | |
23 | dist/ | |
24 | generated/ | |
25 | .vendor/ | |
26 | bin/* | |
27 | gin-bin | |
28 | .idea/ |
0 | { | |
1 | "Enable": ["vet", "golint", "goimports", "deadcode", "gotype", "ineffassign", "misspell", "nakedret", "unconvert", "megacheck", "varcheck"] | |
2 | } |
0 | language: go | |
1 | ||
2 | sudo: false | |
3 | ||
4 | matrix: | |
5 | include: | |
6 | - go: "1.9.x" | |
7 | - go: "1.10.x" | |
8 | - go: "1.11.x" | |
9 | env: | |
10 | - GO111MODULE=off | |
11 | - go: "1.11.x" | |
12 | env: | |
13 | - GO111MODULE=on | |
14 | - go: "tip" | |
15 | env: | |
16 | - GO111MODULE=off | |
17 | - go: "tip" | |
18 | env: | |
19 | - GO111MODULE=on | |
20 | allow_failures: | |
21 | - go: "tip" | |
22 | ||
23 | install: make deps | |
24 | ||
25 | script: make ci-test |
0 | The MIT License (MIT) | |
1 | ||
2 | Copyright (c) 2018 Mark Bates | |
3 | ||
4 | Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | of this software and associated documentation files (the "Software"), to deal | |
6 | in the Software without restriction, including without limitation the rights | |
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | copies of the Software, and to permit persons to whom the Software is | |
9 | furnished to do so, subject to the following conditions: | |
10 | ||
11 | The above copyright notice and this permission notice shall be included in all | |
12 | copies or substantial portions of the Software. | |
13 | ||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
20 | SOFTWARE. |
0 | TAGS ?= "sqlite" | |
1 | GO_BIN ?= go | |
2 | ||
3 | install: | |
4 | packr | |
5 | $(GO_BIN) install -tags ${TAGS} -v . | |
6 | make tidy | |
7 | ||
8 | tidy: | |
9 | ifeq ($(GO111MODULE),on) | |
10 | $(GO_BIN) mod tidy | |
11 | else | |
12 | echo skipping go mod tidy | |
13 | endif | |
14 | ||
15 | deps: | |
16 | $(GO_BIN) get github.com/gobuffalo/release | |
17 | $(GO_BIN) get github.com/gobuffalo/packr/packr | |
18 | $(GO_BIN) get -tags ${TAGS} -t ./... | |
19 | make tidy | |
20 | ||
21 | build: | |
22 | packr | |
23 | $(GO_BIN) build -v . | |
24 | make tidy | |
25 | ||
26 | test: | |
27 | packr | |
28 | $(GO_BIN) test -tags ${TAGS} ./... | |
29 | make tidy | |
30 | ||
31 | ci-test: | |
32 | $(GO_BIN) test -tags ${TAGS} -race ./... | |
33 | make tidy | |
34 | ||
35 | lint: | |
36 | gometalinter --vendor ./... --deadline=1m --skip=internal | |
37 | make tidy | |
38 | ||
39 | update: | |
40 | $(GO_BIN) get -u -tags ${TAGS} | |
41 | make tidy | |
42 | packr | |
43 | make test | |
44 | make install | |
45 | make tidy | |
46 | ||
47 | release-test: | |
48 | $(GO_BIN) test -tags ${TAGS} -race ./... | |
49 | make tidy | |
50 | ||
51 | release: | |
52 | make tidy | |
53 | release -y -f version.go | |
54 | make tidy |
0 | package safe | |
1 | ||
2 | import ( | |
3 | "errors" | |
4 | "fmt" | |
5 | ) | |
6 | ||
7 | // Run the function safely knowing that if it panics | |
8 | // the panic will be caught and returned as an error | |
9 | func Run(fn func()) (err error) { | |
10 | return RunE(func() error { | |
11 | fn() | |
12 | return nil | |
13 | }) | |
14 | } | |
15 | ||
16 | // Run the function safely knowing that if it panics | |
17 | // the panic will be caught and returned as an error | |
18 | func RunE(fn func() error) (err error) { | |
19 | defer func() { | |
20 | if err != nil { | |
21 | return | |
22 | } | |
23 | if ex := recover(); ex != nil { | |
24 | if e, ok := ex.(error); ok { | |
25 | err = e | |
26 | return | |
27 | } | |
28 | err = errors.New(fmt.Sprint(ex)) | |
29 | } | |
30 | }() | |
31 | return fn() | |
32 | } |
0 | # github.com/markbates/safe Stands on the Shoulders of Giants | |
1 | ||
2 | github.com/markbates/safe does not try to reinvent the wheel! Instead, it uses the already great wheels developed by the Go community and puts them all together in the best way possible. Without these giants this project would not be possible. Please make sure to check them out and thank them for all of their hard work. | |
3 | ||
4 | Thank you to the following **GIANTS**: | |
5 | ||
6 | ||
7 | * [github.com/markbates/safe](https://godoc.org/github.com/markbates/safe) |
14 | 14 | |
15 | 15 | // PackOptions ... |
16 | 16 | type PackOptions struct { |
17 | IgnoreImports bool | |
18 | Legacy bool | |
19 | StoreCmd string | |
20 | Roots []string | |
21 | RootsOptions *parser.RootsOptions | |
17 | IgnoreImports bool | |
18 | Legacy bool | |
19 | StoreCmd string | |
20 | Roots []string | |
21 | RootsOptions *parser.RootsOptions | |
22 | 22 | } |
23 | 23 | |
24 | 24 | // Pack the roots given + PWD |
7 | 7 | |
8 | 8 | // Box found while parsing a file |
9 | 9 | type Box struct { |
10 | Name string // name of the box | |
11 | Path string // relative path of folder NewBox("./templates") | |
12 | AbsPath string // absolute path of Path | |
13 | Package string // the package name the box was found in | |
14 | PWD string // the PWD when the parser was run | |
15 | PackageDir string // the absolute path of the package where the box was found | |
10 | Name string // name of the box | |
11 | Path string // relative path of folder NewBox("./templates") | |
12 | AbsPath string // absolute path of Path | |
13 | Package string // the package name the box was found in | |
14 | PWD string // the PWD when the parser was run | |
15 | PackageDir string // the absolute path of the package where the box was found | |
16 | 16 | } |
17 | 17 | |
18 | 18 | type Boxes []*Box |
31 | 31 | name = strings.Replace(name, "\"", "", -1) |
32 | 32 | pwd, _ := os.Getwd() |
33 | 33 | box := &Box{ |
34 | Name: name, | |
35 | Path: path, | |
36 | PWD: pwd, | |
34 | Name: name, | |
35 | Path: path, | |
36 | PWD: pwd, | |
37 | 37 | } |
38 | 38 | return box |
39 | 39 | } |
9 | 9 | // File that is to be parsed |
10 | 10 | type File struct { |
11 | 11 | io.Reader |
12 | Path string | |
13 | AbsPath string | |
12 | Path string | |
13 | AbsPath string | |
14 | 14 | } |
15 | 15 | |
16 | 16 | // Name of the file "app.go" |
46 | 46 | abs, _ = filepath.Abs(path) |
47 | 47 | } |
48 | 48 | return &File{ |
49 | Reader: r, | |
50 | Path: path, | |
51 | AbsPath: abs, | |
49 | Reader: r, | |
50 | Path: path, | |
51 | AbsPath: abs, | |
52 | 52 | } |
53 | 53 | } |
2 | 2 | import ( |
3 | 3 | "fmt" |
4 | 4 | "go/build" |
5 | "os" | |
5 | 6 | "path/filepath" |
6 | 7 | "strings" |
7 | 8 | "time" |
8 | 9 | |
9 | 10 | "github.com/gobuffalo/packr/v2/plog" |
10 | 11 | "github.com/karrick/godirwalk" |
11 | "github.com/gobuffalo/packr/v2/internal/takeon/github.com/markbates/errx" | |
12 | "github.com/gobuffalo/packr/v2/internal/takeon/github.com/markbates/oncer" | |
12 | "github.com/markbates/errx" | |
13 | "github.com/markbates/oncer" | |
13 | 14 | ) |
14 | 15 | |
15 | 16 | type finder struct { |
32 | 33 | if ext != ".go" { |
33 | 34 | return nil |
34 | 35 | } |
36 | //check if path is a dir | |
37 | fi, err := os.Stat(path) | |
38 | if err != nil { | |
39 | return nil | |
40 | } | |
41 | ||
42 | if fi.IsDir() { | |
43 | return nil | |
44 | } | |
45 | ||
35 | 46 | names = append(names, path) |
36 | 47 | return nil |
37 | 48 | } |
38 | 49 | err = godirwalk.Walk(dir, &godirwalk.Options{ |
39 | FollowSymbolicLinks: true, | |
40 | Callback: callback, | |
50 | FollowSymbolicLinks: true, | |
51 | Callback: callback, | |
41 | 52 | }) |
42 | 53 | }) |
43 | 54 |
7 | 7 | "strings" |
8 | 8 | |
9 | 9 | "github.com/gobuffalo/packd" |
10 | "github.com/gobuffalo/packr/v2/internal/takeon/github.com/markbates/errx" | |
10 | "github.com/markbates/errx" | |
11 | 11 | ) |
12 | 12 | |
13 | 13 | // ParsedFile ... |
14 | 14 | type ParsedFile struct { |
15 | File packd.SimpleFile | |
16 | FileSet *token.FileSet | |
17 | Ast *ast.File | |
18 | Lines []string | |
15 | File packd.SimpleFile | |
16 | FileSet *token.FileSet | |
17 | Ast *ast.File | |
18 | Lines []string | |
19 | 19 | } |
20 | 20 | |
21 | 21 | // ParseFileMode ... |
22 | 22 | func ParseFileMode(gf packd.SimpleFile, mode parser.Mode) (ParsedFile, error) { |
23 | 23 | pf := ParsedFile{ |
24 | FileSet: token.NewFileSet(), | |
25 | File: gf, | |
24 | FileSet: token.NewFileSet(), | |
25 | File: gf, | |
26 | 26 | } |
27 | 27 | |
28 | 28 | src := gf.String() |
9 | 9 | |
10 | 10 | // Parser to find boxes |
11 | 11 | type Parser struct { |
12 | Prospects []*File // a list of files to check for boxes | |
13 | IgnoreImports bool | |
12 | Prospects []*File // a list of files to check for boxes | |
13 | IgnoreImports bool | |
14 | 14 | } |
15 | 15 | |
16 | 16 | // Run the parser and run any boxes found |
6 | 6 | |
7 | 7 | "github.com/gobuffalo/packr/v2/jam/parser" |
8 | 8 | "github.com/gobuffalo/packr/v2/jam/store" |
9 | "github.com/gobuffalo/packr/v2/internal/takeon/github.com/markbates/oncer" | |
9 | "github.com/markbates/oncer" | |
10 | 10 | "github.com/stretchr/testify/require" |
11 | 11 | ) |
12 | 12 |
7 | 7 | |
8 | 8 | func Test_IsProspect(t *testing.T) { |
9 | 9 | table := []struct { |
10 | path string | |
11 | pass bool | |
10 | path string | |
11 | pass bool | |
12 | 12 | }{ |
13 | 13 | {"foo/.git/config", false}, |
14 | 14 | {"foo/.git/baz.go", false}, |
12 | 12 | ) |
13 | 13 | |
14 | 14 | type RootsOptions struct { |
15 | IgnoreImports bool | |
16 | Ignores []string | |
15 | IgnoreImports bool | |
16 | Ignores []string | |
17 | 17 | } |
18 | 18 | |
19 | 19 | func (r RootsOptions) String() string { |
48 | 48 | return nil |
49 | 49 | } |
50 | 50 | wopts := &godirwalk.Options{ |
51 | FollowSymbolicLinks: true, | |
52 | Callback: callback, | |
51 | FollowSymbolicLinks: true, | |
52 | Callback: callback, | |
53 | 53 | } |
54 | 54 | for _, root := range roots { |
55 | 55 | plog.Debug(p, "NewFromRoots", "walking", root) |
11 | 11 | ) |
12 | 12 | |
13 | 13 | type Visitor struct { |
14 | File packd.SimpleFile | |
15 | Package string | |
16 | boxes map[string]*Box | |
17 | errors []error | |
14 | File packd.SimpleFile | |
15 | Package string | |
16 | boxes map[string]*Box | |
17 | errors []error | |
18 | 18 | } |
19 | 19 | |
20 | 20 | func NewVisitor(f *File) *Visitor { |
21 | 21 | return &Visitor{ |
22 | File: f, | |
23 | boxes: map[string]*Box{}, | |
24 | errors: []error{}, | |
22 | File: f, | |
23 | boxes: map[string]*Box{}, | |
24 | errors: []error{}, | |
25 | 25 | } |
26 | 26 | } |
27 | 27 |
0 | errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= | |
1 | errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | |
0 | 2 | github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= |
1 | 3 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= |
2 | 4 | github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= |
190 | 192 | github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= |
191 | 193 | github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= |
192 | 194 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= |
193 | errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= | |
194 | errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | |
195 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | |
195 | 196 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= |
196 | 197 | github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= |
197 | 198 | github.com/serenize/snaker v0.0.0-20171204205717-a683aaf2d516/go.mod h1:Yow6lPLSAXx2ifx470yD/nUe22Dv5vBvxK/UK9UUTVs= |
16 | 16 | "strings" |
17 | 17 | "sync" |
18 | 18 | |
19 | "github.com/gobuffalo/envy" | |
19 | "github.com/gobuffalo/packr/v2/internal" | |
20 | "github.com/karrick/godirwalk" | |
21 | ||
20 | 22 | "github.com/gobuffalo/packr/v2/file/resolver/encoding/hex" |
21 | 23 | "github.com/gobuffalo/packr/v2/plog" |
22 | 24 | "github.com/rogpeppe/go-internal/modfile" |
23 | 25 | |
24 | 26 | "github.com/gobuffalo/packr/v2/jam/parser" |
25 | "github.com/karrick/godirwalk" | |
26 | 27 | "golang.org/x/sync/errgroup" |
27 | 28 | ) |
28 | 29 | |
31 | 32 | const DISK_GLOBAL_KEY = "__packr_global__" |
32 | 33 | |
33 | 34 | type Disk struct { |
34 | DBPath string | |
35 | DBPackage string | |
36 | global map[string]string | |
37 | boxes map[string]*parser.Box | |
38 | moot *sync.RWMutex | |
35 | DBPath string | |
36 | DBPackage string | |
37 | global map[string]string | |
38 | boxes map[string]*parser.Box | |
39 | moot *sync.RWMutex | |
39 | 40 | } |
40 | 41 | |
41 | 42 | func NewDisk(path string, pkg string) *Disk { |
49 | 50 | path, _ = filepath.Abs(path) |
50 | 51 | } |
51 | 52 | return &Disk{ |
52 | DBPath: path, | |
53 | DBPackage: pkg, | |
54 | global: map[string]string{}, | |
55 | boxes: map[string]*parser.Box{}, | |
56 | moot: &sync.RWMutex{}, | |
53 | DBPath: path, | |
54 | DBPackage: pkg, | |
55 | global: map[string]string{}, | |
56 | boxes: map[string]*parser.Box{}, | |
57 | moot: &sync.RWMutex{}, | |
57 | 58 | } |
58 | 59 | } |
59 | 60 | |
67 | 68 | return names, nil |
68 | 69 | } |
69 | 70 | err := godirwalk.Walk(path, &godirwalk.Options{ |
70 | FollowSymbolicLinks: true, | |
71 | FollowSymbolicLinks: true, | |
71 | 72 | Callback: func(path string, de *godirwalk.Dirent) error { |
72 | 73 | if !de.IsRegular() { |
73 | 74 | return nil |
125 | 126 | } |
126 | 127 | |
127 | 128 | type options struct { |
128 | Package string | |
129 | GlobalFiles map[string]string | |
130 | Boxes []optsBox | |
131 | GK string | |
129 | Package string | |
130 | GlobalFiles map[string]string | |
131 | Boxes []optsBox | |
132 | GK string | |
132 | 133 | } |
133 | 134 | |
134 | 135 | type optsBox struct { |
135 | Name string | |
136 | Path string | |
136 | Name string | |
137 | Path string | |
137 | 138 | } |
138 | 139 | |
139 | 140 | // Close ... |
144 | 145 | |
145 | 146 | xb := &parser.Box{Name: DISK_GLOBAL_KEY} |
146 | 147 | opts := options{ |
147 | Package: d.DBPackage, | |
148 | GlobalFiles: map[string]string{}, | |
149 | GK: makeKey(xb, d.DBPath), | |
148 | Package: d.DBPackage, | |
149 | GlobalFiles: map[string]string{}, | |
150 | GK: makeKey(xb, d.DBPath), | |
150 | 151 | } |
151 | 152 | |
152 | 153 | wg := errgroup.Group{} |
203 | 204 | } |
204 | 205 | |
205 | 206 | type file struct { |
206 | Resolver string | |
207 | ForwardPath string | |
207 | Resolver string | |
208 | ForwardPath string | |
208 | 209 | } |
209 | 210 | |
210 | 211 | tmpl, err := template.New("box.go").Parse(diskGlobalBoxTmpl) |
217 | 218 | p := strings.TrimPrefix(s, box.AbsPath) |
218 | 219 | p = strings.TrimPrefix(p, string(filepath.Separator)) |
219 | 220 | files = append(files, file{ |
220 | Resolver: strings.Replace(p, "\\", "/", -1), | |
221 | ForwardPath: makeKey(box, s), | |
221 | Resolver: strings.Replace(p, "\\", "/", -1), | |
222 | ForwardPath: makeKey(box, s), | |
222 | 223 | }) |
223 | 224 | } |
224 | 225 | opts := map[string]interface{}{ |
225 | "Box": box, | |
226 | "Files": files, | |
226 | "Box": box, | |
227 | "Files": files, | |
227 | 228 | } |
228 | 229 | |
229 | 230 | bb := &bytes.Buffer{} |
253 | 254 | } |
254 | 255 | |
255 | 256 | var ip string |
256 | if envy.Mods() { | |
257 | if internal.Mods() { | |
257 | 258 | // Starting in 1.12, we can rely on Go's method for |
258 | 259 | // resolving where go.mod resides. Prior versions will |
259 | 260 | // simply return an empty string. |
284 | 285 | ip = strings.Replace(ip, "\\", "/", -1) |
285 | 286 | } else { |
286 | 287 | ip = filepath.Dir(d.DBPath) |
287 | srcs := envy.GoPaths() | |
288 | srcs := internal.GoPaths() | |
288 | 289 | srcs = append(srcs, build.Default.SrcDirs()...) |
289 | 290 | for _, x := range srcs { |
290 | 291 | ip = strings.TrimPrefix(ip, "/private") |
311 | 312 | defer f.Close() |
312 | 313 | |
313 | 314 | o := struct { |
314 | Package string | |
315 | Import string | |
315 | Package string | |
316 | Import string | |
316 | 317 | }{ |
317 | Package: b.Package, | |
318 | Import: ip, | |
318 | Package: b.Package, | |
319 | Import: ip, | |
319 | 320 | } |
320 | 321 | |
321 | 322 | tmpl, err := template.New(p).Parse(diskImportTmpl) |
9 | 9 | g := packr.New(gk, "") |
10 | 10 | |
11 | 11 | hgr, err := resolver.NewHexGzip(map[string]string{ |
12 | "4abf3a9b652ecec6b347eb6acb7ce363": "1f8b08000000000000fff2750c72775508cecc2d28cecfe302040000fffffb1d273b0e000000", | |
13 | "5cfc8f95f98237a10affc14a76e3e20b": "1f8b08000000000000fff2757477f7745508cecc2d28cecfe302040000ffffb09167470f000000", | |
14 | "6d8be986fa35821e7e869fbb118e51ba": "1f8b08000000000000fff2f0f7750d5208cecc2d28cecfe302040000fffffb2ef0a60e000000", | |
15 | "99e5497ae5f5988fafafbcd15ed74d22": "1f8b08000000000000fff2f10c765408cecc2d28cecfe302040000ffffab9bc93e0d000000", | |
16 | "bb006aa6261a80f6c52c640f713659c1": "1f8b08000000000000ff72720c0a5108cecc2d28cecfe302040000ffff89742ac20d000000", | |
12 | "4abf3a9b652ecec6b347eb6acb7ce363": "1f8b08000000000000fff2750c72775508cecc2d28cecfe302040000fffffb1d273b0e000000", | |
13 | "5cfc8f95f98237a10affc14a76e3e20b": "1f8b08000000000000fff2757477f7745508cecc2d28cecfe302040000ffffb09167470f000000", | |
14 | "6d8be986fa35821e7e869fbb118e51ba": "1f8b08000000000000fff2f0f7750d5208cecc2d28cecfe302040000fffffb2ef0a60e000000", | |
15 | "99e5497ae5f5988fafafbcd15ed74d22": "1f8b08000000000000fff2f10c765408cecc2d28cecfe302040000ffffab9bc93e0d000000", | |
16 | "bb006aa6261a80f6c52c640f713659c1": "1f8b08000000000000ff72720c0a5108cecc2d28cecfe302040000ffff89742ac20d000000", | |
17 | 17 | }) |
18 | 18 | if err != nil { |
19 | 19 | return err |
44 | 44 | const diskGlobalBoxTmpl = ` |
45 | 45 | func() { |
46 | 46 | b := packr.New("{{.Box.Name}}", "{{.Box.Path}}") |
47 | {{ range $file := .Files -}} | |
47 | {{- range $file := .Files }} | |
48 | 48 | b.SetResolver("{{$file.Resolver}}", packr.Pointer{ForwardBox: gk, ForwardPath: "{{$file.ForwardPath}}"}) |
49 | {{ end -}} | |
50 | }() | |
51 | ` | |
49 | {{- end }} | |
50 | }()` |
8 | 8 | var _ Store = &FnStore{} |
9 | 9 | |
10 | 10 | type FnStore struct { |
11 | FileNamesFn func(*parser.Box) ([]string, error) | |
12 | FilesFn func(*parser.Box) ([]*parser.File, error) | |
13 | PackFn func(*parser.Box) error | |
14 | CleanFn func(*parser.Box) error | |
11 | FileNamesFn func(*parser.Box) ([]string, error) | |
12 | FilesFn func(*parser.Box) ([]*parser.File, error) | |
13 | PackFn func(*parser.Box) error | |
14 | CleanFn func(*parser.Box) error | |
15 | 15 | } |
16 | 16 | |
17 | 17 | func (f *FnStore) FileNames(box *parser.Box) ([]string, error) { |
16 | 16 | |
17 | 17 | type Legacy struct { |
18 | 18 | *Disk |
19 | boxes map[string][]legacyBox | |
19 | boxes map[string][]legacyBox | |
20 | 20 | } |
21 | 21 | |
22 | 22 | func NewLegacy() *Legacy { |
23 | 23 | return &Legacy{ |
24 | Disk: NewDisk("", ""), | |
25 | boxes: map[string][]legacyBox{}, | |
24 | Disk: NewDisk("", ""), | |
25 | boxes: map[string][]legacyBox{}, | |
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
49 | 49 | |
50 | 50 | lbs := l.boxes[box.PackageDir] |
51 | 51 | lbs = append(lbs, legacyBox{ |
52 | Box: box, | |
53 | Files: fcs, | |
52 | Box: box, | |
53 | Files: fcs, | |
54 | 54 | }) |
55 | 55 | l.boxes[box.PackageDir] = lbs |
56 | 56 | return nil |
77 | 77 | bx := b[0].Box |
78 | 78 | pkg := bx.Package |
79 | 79 | opts := map[string]interface{}{ |
80 | "Package": pkg, | |
81 | "Boxes": b, | |
80 | "Package": pkg, | |
81 | "Boxes": b, | |
82 | 82 | } |
83 | 83 | p := filepath.Join(bx.PackageDir, "a_"+bx.Package+"-packr.go.tmpl") |
84 | 84 | tmpl, err := template.New(p).Parse(legacyTmpl) |
101 | 101 | } |
102 | 102 | |
103 | 103 | type legacyBox struct { |
104 | Box *parser.Box | |
105 | Files []legacyFile | |
104 | Box *parser.Box | |
105 | Files []legacyFile | |
106 | 106 | } |
107 | 107 | |
108 | 108 | type legacyFile struct { |
109 | Name string | |
110 | Contents string | |
109 | Name string | |
110 | Contents string | |
111 | 111 | } |
112 | 112 | |
113 | 113 | var legacyTmpl = `// Code generated by github.com/gobuffalo/packr. DO NOT EDIT. |
121 | 121 | func init() { |
122 | 122 | {{- range $box := .Boxes }} |
123 | 123 | {{- range $box.Files }} |
124 | packr.PackJSONBytes("{{$box.Box.Name}}", "{{.Name}}", "{{.Contents}}") | |
124 | _ = packr.PackJSONBytes("{{$box.Box.Name}}", "{{.Name}}", "{{.Contents}}") | |
125 | 125 | {{- end }} |
126 | 126 | {{- end }} |
127 | 127 | } |
3 | 3 | "fmt" |
4 | 4 | |
5 | 5 | "github.com/gobuffalo/packr/v2/file/resolver" |
6 | "github.com/gobuffalo/packr/v2/internal/takeon/github.com/markbates/safe" | |
7 | 6 | "github.com/gobuffalo/packr/v2/jam/parser" |
8 | 7 | "github.com/gobuffalo/packr/v2/plog" |
8 | "github.com/markbates/safe" | |
9 | 9 | ) |
10 | 10 | |
11 | 11 | var boxes = &boxMap{} |
7 | 7 | ) |
8 | 8 | |
9 | 9 | var buildCmd = &cobra.Command{ |
10 | Use: "build", | |
11 | Short: "Wraps the go build command with packr", | |
12 | DisableFlagParsing: true, | |
10 | Use: "build", | |
11 | Short: "Wraps the go build command with packr", | |
12 | DisableFlagParsing: true, | |
13 | 13 | RunE: func(cmd *cobra.Command, args []string) error { |
14 | 14 | cargs := parseArgs(args) |
15 | 15 | if globalOptions.Verbose { |
5 | 5 | ) |
6 | 6 | |
7 | 7 | var cleanCmd = &cobra.Command{ |
8 | Use: "clean", | |
9 | Short: "removes any *-packr.go files", | |
8 | Use: "clean", | |
9 | Short: "removes any *-packr.go files", | |
10 | 10 | RunE: func(cmd *cobra.Command, args []string) error { |
11 | 11 | return jam.Clean(args...) |
12 | 12 | }, |
5 | 5 | "os" |
6 | 6 | "strings" |
7 | 7 | |
8 | "github.com/gobuffalo/envy" | |
9 | 8 | "github.com/gobuffalo/packr/v2/jam/store" |
10 | 9 | ) |
11 | ||
12 | var modsOn = (strings.TrimSpace(envy.Get("GO111MODULE", "off")) == "on") | |
13 | 10 | |
14 | 11 | //YesToAll will be used by the command to skip the questions |
15 | 12 | var YesToAll bool |
9 | 9 | |
10 | 10 | // fixCmd represents the info command |
11 | 11 | var fixCmd = &cobra.Command{ |
12 | Use: "fix", | |
13 | Short: fmt.Sprintf("will attempt to fix a application's API to match packr version %s", packr.Version), | |
12 | Use: "fix", | |
13 | Short: fmt.Sprintf("will attempt to fix a application's API to match packr version %s", packr.Version), | |
14 | 14 | RunE: func(cmd *cobra.Command, args []string) error { |
15 | 15 | return fix.Run() |
16 | 16 | }, |
6 | 6 | "path/filepath" |
7 | 7 | "strings" |
8 | 8 | |
9 | "github.com/gobuffalo/envy" | |
10 | 9 | "github.com/gobuffalo/packr/v2/plog" |
11 | 10 | ) |
12 | 11 | |
54 | 53 | } |
55 | 54 | } |
56 | 55 | |
57 | cp := exec.Command(envy.Get("GO_BIN", "go"), cargs...) | |
56 | goBin := os.Getenv("GO_BIN") | |
57 | if goBin == "" { | |
58 | goBin = "go" | |
59 | } | |
60 | cp := exec.Command(goBin, cargs...) | |
58 | 61 | plog.Logger.Debug(strings.Join(cp.Args, " ")) |
59 | 62 | cp.Stderr = os.Stderr |
60 | 63 | cp.Stdin = os.Stdin |
22 | 22 | ` |
23 | 23 | |
24 | 24 | var installCmd = &cobra.Command{ |
25 | Use: "install", | |
26 | Short: "Don't. ru", | |
27 | DisableFlagParsing: true, | |
25 | Use: "install", | |
26 | Short: "Don't. ru", | |
27 | DisableFlagParsing: true, | |
28 | 28 | RunE: func(cmd *cobra.Command, args []string) error { |
29 | 29 | cargs := parseArgs(args) |
30 | 30 | if globalOptions.Verbose { |
11 | 11 | |
12 | 12 | var globalOptions = struct { |
13 | 13 | jam.PackOptions |
14 | Verbose bool | |
15 | Silent bool | |
14 | Verbose bool | |
15 | Silent bool | |
16 | 16 | }{ |
17 | 17 | PackOptions: jam.PackOptions{}, |
18 | 18 | } |
19 | 19 | |
20 | 20 | var rootCmd = &cobra.Command{ |
21 | Use: "packr2", | |
22 | Short: "Packr is a simple solution for bundling static assets inside of Go binaries.", | |
21 | Use: "packr2", | |
22 | Short: "Packr is a simple solution for bundling static assets inside of Go binaries.", | |
23 | 23 | PersistentPreRunE: func(cmd *cobra.Command, args []string) error { |
24 | 24 | for _, a := range args { |
25 | 25 | if a == "--legacy" { |
7 | 7 | ) |
8 | 8 | |
9 | 9 | var versionCmd = &cobra.Command{ |
10 | Use: "version", | |
11 | Short: "shows packr version", | |
10 | Use: "version", | |
11 | Short: "shows packr version", | |
12 | 12 | RunE: func(cmd *cobra.Command, args []string) error { |
13 | fmt.Print(packr.Version) | |
13 | fmt.Println(packr.Version) | |
14 | 14 | return nil |
15 | 15 | }, |
16 | 16 | } |
8 | 8 | // Pointer is a resolvr which resolves |
9 | 9 | // a file from a different box. |
10 | 10 | type Pointer struct { |
11 | ForwardBox string | |
12 | ForwardPath string | |
11 | ForwardBox string | |
12 | ForwardPath string | |
13 | 13 | } |
14 | 14 | |
15 | 15 | var _ resolver.Resolver = Pointer{} |
14 | 14 | |
15 | 15 | b2 := New("b2", "") |
16 | 16 | b2.SetResolver("bar.txt", &Pointer{ |
17 | ForwardBox: "b1", | |
18 | ForwardPath: "foo.txt", | |
17 | ForwardBox: "b1", | |
18 | ForwardPath: "foo.txt", | |
19 | 19 | }) |
20 | 20 | |
21 | 21 | s, err := b2.FindString("bar.txt") |