updated .drone.yml
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Paul 2020-08-01 19:09:09 +02:00
parent 573d8f49e4
commit 9aecb2f01e
46 changed files with 7 additions and 2541 deletions

View File

@ -8,7 +8,7 @@ steps:
image: golang image: golang
commands: commands:
- go get -u github.com/gobuffalo/packr/v2/packr2 - go get -u github.com/gobuffalo/packr/v2/packr2
- go build -o packr2 github.com/gobuffalo/packr/v2/packr2 - go build -o packr2 -mod=mod github.com/gobuffalo/packr/v2/packr2
- name: build - name: build
image: golang image: golang
commands: commands:
@ -39,7 +39,7 @@ steps:
image: golang image: golang
commands: commands:
- go get -u github.com/gobuffalo/packr/v2/packr2 - go get -u github.com/gobuffalo/packr/v2/packr2
- go build -o packr2 github.com/gobuffalo/packr/v2/packr2 - go build -o packr2 -mod=mod github.com/gobuffalo/packr/v2/packr2
- name: build - name: build
image: golang image: golang
commands: commands:

3
go.mod
View File

@ -5,12 +5,11 @@ go 1.14
require ( require (
github.com/gobuffalo/packr/v2 v2.8.0 github.com/gobuffalo/packr/v2 v2.8.0
github.com/karrick/godirwalk v1.15.6 // indirect github.com/karrick/godirwalk v1.15.6 // indirect
github.com/labstack/echo v3.3.10+incompatible // indirect
github.com/labstack/echo/v4 v4.1.16 github.com/labstack/echo/v4 v4.1.16
github.com/likexian/whois-go v1.6.1 github.com/likexian/whois-go v1.6.1
github.com/likexian/whois-parser-go v1.14.4 github.com/likexian/whois-parser-go v1.14.4
github.com/markbates/pkger v0.16.0
github.com/sirupsen/logrus v1.6.0 // indirect github.com/sirupsen/logrus v1.6.0 // indirect
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 // indirect golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 // indirect
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
gopkg.in/yaml.v2 v2.2.7 // indirect
) )

7
go.sum
View File

@ -28,13 +28,10 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gobuffalo/here v0.6.0 h1:hYrd0a6gDmWxBM4TnrGw8mQg24iSVoIkHEk7FodQcBI=
github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM=
github.com/gobuffalo/logger v1.0.3 h1:YaXOTHNPCvkqqA7w05A4v0k2tCdpr+sgFlgINbQ6gqc= github.com/gobuffalo/logger v1.0.3 h1:YaXOTHNPCvkqqA7w05A4v0k2tCdpr+sgFlgINbQ6gqc=
github.com/gobuffalo/logger v1.0.3/go.mod h1:SoeejUwldiS7ZsyCBphOGURmWdwUFXs0J7TCjEhjKxM= github.com/gobuffalo/logger v1.0.3/go.mod h1:SoeejUwldiS7ZsyCBphOGURmWdwUFXs0J7TCjEhjKxM=
github.com/gobuffalo/packd v1.0.0 h1:6ERZvJHfe24rfFmA9OaoKBdC7+c9sydrytMg8SdFGBM= github.com/gobuffalo/packd v1.0.0 h1:6ERZvJHfe24rfFmA9OaoKBdC7+c9sydrytMg8SdFGBM=
github.com/gobuffalo/packd v1.0.0/go.mod h1:6VTc4htmJRFB7u1m/4LeMTWjFoYrUiBkU9Fdec9hrhI= github.com/gobuffalo/packd v1.0.0/go.mod h1:6VTc4htmJRFB7u1m/4LeMTWjFoYrUiBkU9Fdec9hrhI=
github.com/gobuffalo/packr v1.30.1 h1:hu1fuVR3fXEZR7rXNW3h8rqSML8EVAf6KNm0NKO/wKg=
github.com/gobuffalo/packr/v2 v2.8.0 h1:IULGd15bQL59ijXLxEvA5wlMxsmx/ZkQv9T282zNVIY= github.com/gobuffalo/packr/v2 v2.8.0 h1:IULGd15bQL59ijXLxEvA5wlMxsmx/ZkQv9T282zNVIY=
github.com/gobuffalo/packr/v2 v2.8.0/go.mod h1:PDk2k3vGevNE3SwVyVRgQCCXETC9SaONCNSXT1Q8M1g= github.com/gobuffalo/packr/v2 v2.8.0/go.mod h1:PDk2k3vGevNE3SwVyVRgQCCXETC9SaONCNSXT1Q8M1g=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
@ -72,8 +69,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg=
github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
github.com/labstack/echo/v4 v4.1.16 h1:8swiwjE5Jkai3RPfZoahp8kjVCRNq+y7Q0hPji2Kz0o= github.com/labstack/echo/v4 v4.1.16 h1:8swiwjE5Jkai3RPfZoahp8kjVCRNq+y7Q0hPji2Kz0o=
github.com/labstack/echo/v4 v4.1.16/go.mod h1:awO+5TzAjvL8XpibdsfXxPgHr+orhtXZJZIQCVjogKI= github.com/labstack/echo/v4 v4.1.16/go.mod h1:awO+5TzAjvL8XpibdsfXxPgHr+orhtXZJZIQCVjogKI=
github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0= github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0=
@ -90,8 +85,6 @@ github.com/markbates/errx v1.1.0 h1:QDFeR+UP95dO12JgW+tgi2UVfo0V8YBHiUIOaeBPiEI=
github.com/markbates/errx v1.1.0/go.mod h1:PLa46Oex9KNbVDZhKel8v1OT7hD5JZ2eI7AHhA0wswc= github.com/markbates/errx v1.1.0/go.mod h1:PLa46Oex9KNbVDZhKel8v1OT7hD5JZ2eI7AHhA0wswc=
github.com/markbates/oncer v1.0.0 h1:E83IaVAHygyndzPimgUYJjbshhDTALZyXxvk9FOlQRY= github.com/markbates/oncer v1.0.0 h1:E83IaVAHygyndzPimgUYJjbshhDTALZyXxvk9FOlQRY=
github.com/markbates/oncer v1.0.0/go.mod h1:Z59JA581E9GP6w96jai+TGqafHPW+cPfRxz2aSZ0mcI= github.com/markbates/oncer v1.0.0/go.mod h1:Z59JA581E9GP6w96jai+TGqafHPW+cPfRxz2aSZ0mcI=
github.com/markbates/pkger v0.16.0 h1:bZGAXW80/vi6ORfJCDVQhT8/9raoPdGAhvFd9Yq0LMA=
github.com/markbates/pkger v0.16.0/go.mod h1:0JoVlrol20BSywW79rN3kdFFsE5xYM+rSCQDXbLhiuI=
github.com/markbates/safe v1.0.1 h1:yjZkbvRM6IzKj9tlu/zMJLS0n/V351OZWRnF3QfaUxI= github.com/markbates/safe v1.0.1 h1:yjZkbvRM6IzKj9tlu/zMJLS0n/V351OZWRnF3QfaUxI=
github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=

View File

@ -1,16 +1,12 @@
package templates package templates
import ( import (
"fmt"
"html/template" "html/template"
"io" "io"
"io/ioutil"
"os"
"strings" "strings"
"github.com/gobuffalo/packr/v2" "github.com/gobuffalo/packr/v2"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/markbates/pkger"
) )
// Render is a method that render templates // Render is a method that render templates
@ -37,6 +33,7 @@ func BuildTemplates(box *packr.Box) (builttemplates *Template, err error) {
return return
} }
/*
// BuildTemplatesDir converts packr packages to html/template // BuildTemplatesDir converts packr packages to html/template
func BuildTemplatesDir(dir string) (builttemplates *Template, err error) { func BuildTemplatesDir(dir string) (builttemplates *Template, err error) {
tmpl := template.New("templates") tmpl := template.New("templates")
@ -57,7 +54,7 @@ func BuildTemplatesDir(dir string) (builttemplates *Template, err error) {
} }
return return
} }*/
// Template is a template struct // Template is a template struct
type Template struct { type Template struct {

View File

@ -1,28 +0,0 @@
*.log
.DS_Store
doc
tmp
pkg
*.pid
coverage
coverage.data
build/*
*.pbxuser
*.mode1v3
.svn
profile
.console_history
.sass-cache/*
solr/
.jhw-cache/
jhw.*
*.sublime*
node_modules/
dist/
generated/
.vendor/
bin/*
gin-bin
.idea/
.vscode
cover.out

View File

@ -1,45 +0,0 @@
builds:
-
main: ./cmd/here/main.go
env:
- CGO_ENABLED=0
ldflags:
- -s -w -X "github.com/gobuffalo/here.Version={{.Tag}}"
goos:
- darwin
- linux
- windows
goarch:
- amd64
- 386
- arm
- arm64
goarm:
- 6
- 7
archives:
-
replacements:
'386': i386
darwin: Darwin
linux: Linux
windows: Windows
amd64: x86_64
checksum:
name_template: checksums.txt
snapshot:
name_template: '{{ .Tag }}-next'
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
brews:
-
name: 'here'
github:
owner: 'gobuffalo'
name: 'homebrew-tap'
install: |
bin.install "here"

View File

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2019 Mark Bates
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,50 +0,0 @@
TAGS ?= ""
GO_BIN ?= "go"
install: tidy
cd ./cmd/here && $(GO_BIN) install -tags ${TAGS} -v .
make tidy
tidy:
$(GO_BIN) mod tidy -v
build: tidy
$(GO_BIN) build -v .
make tidy
test: tidy
$(GO_BIN) test -count 1 -cover -tags ${TAGS} -timeout 10s ./...
make tidy
cov:
$(GO_BIN) test -coverprofile cover.out -count 1 -tags ${TAGS} ./...
go tool cover -html cover.out
make tidy
ci-test:
$(GO_BIN) test -tags ${TAGS} -race ./...
lint:
go get github.com/golangci/golangci-lint/cmd/golangci-lint
golangci-lint run --enable-all
make tidy
update:
rm go.*
$(GO_BIN) mod init
$(GO_BIN) mod tidy
make test
make install
make tidy
release-test:
$(GO_BIN) test -tags ${TAGS} -race ./...
make tidy
release:
make tidy
release -y -f version.go --skip-packr
make tidy

View File

@ -1,277 +0,0 @@
# Here
[![](https://github.com/gobuffalo/here/workflows/Tests/badge.svg)](https://github.com/gobuffalo/here/actions)
[![GoDoc](https://godoc.org/github.com/gobuffalo/here?status.svg)](https://godoc.org/github.com/gobuffalo/here)
Here will get you **accurate** Go information about the directory of package requested.
### Requirements
* Go 1.13+
* Go Modules
## CLI
While you can use the tool via its API, you can also use the CLI to get a JSON version of the data.
### Installation
```bash
$ go get github.com/gobuffalo/here/cmd/here
```
### Usage
#### Default
```bash
$ here
{
"Dir": "$GOPATH/src/github.com/gobuffalo/here",
"ImportPath": "github.com/gobuffalo/here",
"Name": "here",
"Doc": "",
"Target": "$GOPATH/pkg/darwin_amd64/github.com/gobuffalo/here.a",
"Root": "$GOPATH",
"Match": [
"."
],
"Stale": true,
"StaleReason": "not installed but available in build cache",
"GoFiles": [
"current.go",
"dir.go",
"here.go",
"info.go",
"info_map.go",
"module.go",
"pkg.go",
"version.go"
],
"Imports": [
"bytes",
"encoding/json",
"fmt",
"os",
"os/exec",
"path/filepath",
"regexp",
"sync"
],
"Deps": [
"bytes",
"context",
"encoding",
"encoding/base64",
"encoding/binary",
"encoding/json",
"errors",
"fmt",
"internal/bytealg",
"internal/cpu",
"internal/fmtsort",
"internal/oserror",
"internal/poll",
"internal/race",
"internal/reflectlite",
"internal/syscall/unix",
"internal/testlog",
"io",
"math",
"math/bits",
"os",
"os/exec",
"path/filepath",
"reflect",
"regexp",
"regexp/syntax",
"runtime",
"runtime/internal/atomic",
"runtime/internal/math",
"runtime/internal/sys",
"sort",
"strconv",
"strings",
"sync",
"sync/atomic",
"syscall",
"time",
"unicode",
"unicode/utf16",
"unicode/utf8",
"unsafe"
],
"TestGoFiles": [
"current_test.go",
"dir_test.go",
"here_test.go",
"info_test.go",
"module_test.go",
"pkg_test.go"
],
"TestImports": [
"github.com/stretchr/testify/require",
"os",
"path/filepath",
"testing"
],
"Module": {
"Path": "github.com/gobuffalo/here",
"Main": true,
"Dir": "$GOPATH/src/github.com/gobuffalo/here",
"GoMod": "$GOPATH/src/github.com/gobuffalo/here/go.mod",
"GoVersion": "1.13"
}
}
```
#### By Directory
```bash
$ here cmd/here
{
"Dir": "$GOPATH/src/github.com/gobuffalo/here/cmd/here",
"ImportPath": "github.com/gobuffalo/here/cmd/here",
"Name": "main",
"Doc": "",
"Target": "$GOPATH/bin/here",
"Root": "$GOPATH",
"Match": [
"."
],
"Stale": false,
"StaleReason": "",
"GoFiles": [
"main.go"
],
"Imports": [
"fmt",
"github.com/gobuffalo/here",
"log",
"os",
"os/exec"
],
"Deps": [
"bytes",
"context",
"encoding",
"encoding/base64",
"encoding/binary",
"encoding/json",
"errors",
"fmt",
"github.com/gobuffalo/here",
"internal/bytealg",
"internal/cpu",
"internal/fmtsort",
"internal/oserror",
"internal/poll",
"internal/race",
"internal/reflectlite",
"internal/syscall/unix",
"internal/testlog",
"io",
"log",
"math",
"math/bits",
"os",
"os/exec",
"path/filepath",
"reflect",
"regexp",
"regexp/syntax",
"runtime",
"runtime/internal/atomic",
"runtime/internal/math",
"runtime/internal/sys",
"sort",
"strconv",
"strings",
"sync",
"sync/atomic",
"syscall",
"time",
"unicode",
"unicode/utf16",
"unicode/utf8",
"unsafe"
],
"TestGoFiles": null,
"TestImports": null,
"Module": {
"Path": "github.com/gobuffalo/here",
"Main": true,
"Dir": "$GOPATH/src/github.com/gobuffalo/here",
"GoMod": "$GOPATH/src/github.com/gobuffalo/here/go.mod",
"GoVersion": "1.13"
}
}
```
#### By Package
```bash
$ here pkg github.com/gobuffalo/genny
{
"Dir": "$GOPATH/pkg/mod/github.com/gobuffalo/genny@v0.4.1",
"ImportPath": "github.com/gobuffalo/genny",
"Name": "genny",
"Doc": "Package genny is a _framework_ for writing modular generators, it however, doesn't actually generate anything.",
"Target": "",
"Root": "$GOPATH/pkg/mod/github.com/gobuffalo/genny@v0.4.1",
"Match": [
"github.com/gobuffalo/genny"
],
"Stale": true,
"StaleReason": "build ID mismatch",
"GoFiles": [
"confirm.go",
"dir.go",
"disk.go",
"dry_runner.go",
"events.go",
"file.go",
"force.go",
"generator.go",
"genny.go",
"group.go",
"helpers.go",
"logger.go",
"replacer.go",
"results.go",
"runner.go",
"step.go",
"transformer.go",
"version.go",
"wet_runner.go"
],
"Imports": null,
"Deps": null,
"TestGoFiles": [
"dry_runner_test.go",
"file_test.go",
"force_test.go",
"generator_test.go",
"genny_test.go",
"group_test.go",
"helpers_test.go",
"replacer_test.go",
"results_test.go",
"runner_test.go",
"step_test.go",
"transformer_test.go",
"wet_runner_test.go"
],
"TestImports": null,
"Module": {
"Path": "github.com/gobuffalo/genny",
"Main": false,
"Dir": "$GOPATH/pkg/mod/github.com/gobuffalo/genny@v0.4.1",
"GoMod": "$GOPATH/pkg/mod/cache/download/github.com/gobuffalo/genny/@v/v0.4.1.mod",
"GoVersion": "1.13"
}
}
```

View File

@ -1,24 +0,0 @@
# github.com/gobuffalo/here Stands on the Shoulders of Giants
github.com/gobuffalo/here 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.
Thank you to the following **GIANTS**:
* [github.com/davecgh/go-spew](https://godoc.org/github.com/davecgh/go-spew)
* [github.com/kr/pretty](https://godoc.org/github.com/kr/pretty)
* [github.com/kr/pty](https://godoc.org/github.com/kr/pty)
* [github.com/kr/text](https://godoc.org/github.com/kr/text)
* [github.com/pmezard/go-difflib](https://godoc.org/github.com/pmezard/go-difflib)
* [github.com/stretchr/objx](https://godoc.org/github.com/stretchr/objx)
* [github.com/stretchr/testify](https://godoc.org/github.com/stretchr/testify)
* [gopkg.in/check.v1](https://godoc.org/gopkg.in/check.v1)
* [gopkg.in/yaml.v2](https://godoc.org/gopkg.in/yaml.v2)

View File

@ -1,31 +0,0 @@
package here
import (
"path/filepath"
)
// Current returns the Info representing the current Go module
func (h Here) Current() (Info, error) {
hp := &h
(&hp.curOnce).Do(func() {
b, err := run("go", "env", "GOMOD")
if err != nil {
hp.curErr = err
return
}
root := filepath.Dir(string(b))
i, err := h.Dir(root)
if err != nil {
hp.curErr = err
return
}
hp.current = i
})
return h.current, h.curErr
}
// Current returns the Info representing the current Go module
func Current() (Info, error) {
return New().Current()
}

View File

@ -1,83 +0,0 @@
package here
import (
"encoding/json"
"os"
"path/filepath"
)
// Dir attempts to gather info for the requested directory.
func (h Here) Dir(p string) (Info, error) {
i, err := h.cache(p, func(p string) (Info, error) {
var i Info
fi, err := os.Stat(p)
if err != nil {
return i, err
}
if !fi.IsDir() {
p = filepath.Dir(p)
}
pwd, err := os.Getwd()
if err != nil {
return i, err
}
defer os.Chdir(pwd)
os.Chdir(p)
b, err := run("go", "list", "-json")
// go: cannot find main module; see 'go help modules'
// build .: cannot find module for path .
// no Go files in
if err != nil {
if nonGoDirRx.MatchString(err.Error()) {
return fromNonGoDir(p)
}
return i, err
}
if err := json.Unmarshal(b, &i); err != nil {
return i, err
}
return i, nil
})
if err != nil {
return i, err
}
return h.cache(i.ImportPath, func(p string) (Info, error) {
return i, nil
})
}
// Dir attempts to gather info for the requested directory.
func Dir(p string) (Info, error) {
return New().Dir(p)
}
func fromNonGoDir(dir string) (Info, error) {
i := Info{
Dir: dir,
Name: filepath.Base(dir),
}
b, err := run("go", "list", "-json", "-m")
if err != nil {
if nonGoDirRx.MatchString(err.Error()) {
return i, nil
}
return i, err
}
if err := json.Unmarshal(b, &i.Module); err != nil {
return i, err
}
return i, err
}

View File

@ -1,11 +0,0 @@
module github.com/gobuffalo/here
go 1.13
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/stretchr/testify v1.4.0
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v2 v2.2.7 // indirect
)

View File

@ -1,19 +0,0 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View File

@ -1,57 +0,0 @@
package here
import (
"bytes"
"fmt"
"os/exec"
"regexp"
"sync"
)
type Here struct {
infos *infoMap
curOnce sync.Once
curErr error
current Info
}
// New returns a Here type that will cache
// all results. This speeds up repeated calls,
// and can be useful for testing.
func New() Here {
return Here{
infos: &infoMap{
data: &sync.Map{},
},
}
}
func run(n string, args ...string) ([]byte, error) {
c := exec.Command(n, args...)
bb := &bytes.Buffer{}
ebb := &bytes.Buffer{}
c.Stdout = bb
c.Stderr = ebb
err := c.Run()
if err != nil {
return nil, fmt.Errorf("%s: %s", err, ebb)
}
return bb.Bytes(), nil
}
func (h Here) cache(p string, fn func(string) (Info, error)) (Info, error) {
i, ok := h.infos.Load(p)
if ok {
return i, nil
}
i, err := fn(p)
if err != nil {
return i, err
}
h.infos.Store(p, i)
return i, nil
}
var nonGoDirRx = regexp.MustCompile(`cannot find main|go help modules|go: |build .:|no Go files|can't load package|not using modules`)

View File

@ -1,39 +0,0 @@
package here
import (
"encoding/json"
)
// Info represents details about the directory/package
type Info struct {
Dir string
ImportPath string
Name string
Doc string
Target string
Root string
Match []string
Stale bool
StaleReason string
GoFiles []string
Imports []string
Deps []string
TestGoFiles []string
TestImports []string
Module Module
}
// IsZero checks if the type has been filled
// with rich chocolately data goodness
func (i Info) IsZero() bool {
return i.String() == Info{}.String()
}
func (i Info) String() string {
b, err := json.MarshalIndent(i, "", " ")
if err != nil {
return err.Error()
}
s := string(b)
return s
}

View File

@ -1,32 +0,0 @@
// Code generated by github.com/gobuffalo/mapgen. DO NOT EDIT.
package here
import (
"sync"
)
// infoMap wraps sync.Map and uses the following types:
// key: string
// value: Info
type infoMap struct {
data *sync.Map
}
// Load the key from the map.
// Returns Info or bool.
// A false return indicates either the key was not found
// or the value is not of type Info
func (m *infoMap) Load(key string) (Info, bool) {
i, ok := m.data.Load(key)
if !ok {
return Info{}, false
}
s, ok := i.(Info)
return s, ok
}
// Store a Info in the map
func (m *infoMap) Store(key string, value Info) {
m.data.Store(key, value)
}

View File

@ -1,29 +0,0 @@
package here
import (
"encoding/json"
)
type Module struct {
Path string
Main bool
Dir string
GoMod string
GoVersion string
}
func (i Module) String() string {
b, err := json.MarshalIndent(i, "", " ")
if err != nil {
return err.Error()
}
return string(b)
}
func (i Module) IsZero() bool {
const cla = "command-line-arguments"
if i.Path == cla {
i.Path = ""
}
return i.String() == Module{}.String()
}

View File

@ -1,63 +0,0 @@
package here
import (
"fmt"
"path/filepath"
"regexp"
"strings"
)
func (i Info) Parse(p string) (Path, error) {
p = strings.TrimSpace(p)
p = filepath.Clean(p)
p = strings.TrimPrefix(p, i.Dir)
p = strings.Replace(p, "\\", "/", -1)
p = strings.TrimSpace(p)
if len(p) == 0 || p == ":" || p == "." {
return i.build("", "", "")
}
res := pathrx.FindAllStringSubmatch(p, -1)
if len(res) == 0 {
return Path{}, fmt.Errorf("could not parse %q", p)
}
matches := res[0]
if len(matches) != 4 {
return Path{}, fmt.Errorf("could not parse %q", p)
}
return i.build(p, matches[1], matches[3])
}
func (i Info) build(p, pkg, name string) (Path, error) {
pt := Path{
Pkg: pkg,
Name: name,
}
if strings.HasPrefix(pt.Pkg, "/") || len(pt.Pkg) == 0 {
pt.Name = pt.Pkg
pt.Pkg = i.Module.Path
}
if len(pt.Name) == 0 {
pt.Name = "/"
}
if pt.Pkg == pt.Name {
pt.Pkg = i.Module.Path
pt.Name = "/"
}
if !strings.HasPrefix(pt.Name, "/") {
pt.Name = "/" + pt.Name
}
pt.Name = strings.TrimPrefix(pt.Name, i.Dir)
return pt, nil
}
var pathrx = regexp.MustCompile("([^:]+)(:(/.+))?")

View File

@ -1,20 +0,0 @@
package here
import (
"fmt"
)
type Path struct {
Pkg string
Name string
}
func (p Path) String() string {
if p.Name == "" {
p.Name = "/"
}
if p.Pkg == "" {
return p.Name
}
return fmt.Sprintf("%s:%s", p.Pkg, p.Name)
}

View File

@ -1,57 +0,0 @@
package here
import (
"encoding/json"
"fmt"
)
// Package attempts to gather info for the requested package.
//
// From the `go help list` docs:
// The -find flag causes list to identify the named packages but not
// resolve their dependencies: the Imports and Deps lists will be empty.
//
// A workaround for this issue is to use the `Dir` field in the
// returned `Info` value and pass it to the `Dir(string) (Info, error)`
// function to return the complete data.
func (h Here) Package(p string) (Info, error) {
i, err := h.cache(p, func(p string) (Info, error) {
var i Info
if len(p) == 0 || p == "." {
return i, fmt.Errorf("missing package name")
}
b, err := run("go", "list", "-json", "-find", p)
if err != nil {
return i, err
}
if err := json.Unmarshal(b, &i); err != nil {
return i, err
}
return i, nil
})
if err != nil {
return i, err
}
h.cache(i.Dir, func(p string) (Info, error) {
return i, nil
})
return i, nil
}
// Package attempts to gather info for the requested package.
//
// From the `go help list` docs:
// The -find flag causes list to identify the named packages but not
// resolve their dependencies: the Imports and Deps lists will be empty.
//
// A workaround for this issue is to use the `Dir` field in the
// returned `Info` value and pass it to the `Dir(string) (Info, error)`
// function to return the complete data.
func Package(p string) (Info, error) {
return New().Package(p)
}

View File

@ -1,4 +0,0 @@
package here
// Version of here
var Version = "development"

View File

@ -1,35 +0,0 @@
.fstest
*.log
.DS_Store
doc
tmp
pkg
*.gem
*.pid
coverage
coverage.data
build/*
*.pbxuser
*.mode1v3
.svn
profile
.console_history
.sass-cache/*
.rake_tasks~
*.log.lck
solr/
.jhw-cache/
jhw.*
*.sublime*
node_modules/
dist/
generated/
.vendor/
bin/*
gin-bin
.idea/
pkged.go
cover.out
.pkgtest
example
app

View File

@ -1,45 +0,0 @@
builds:
-
main: ./cmd/pkger/main.go
env:
- CGO_ENABLED=0
ldflags:
- -s -w -X "github.com/markbates/pkger.Version={{.Tag}}"
goos:
- darwin
- linux
- windows
goarch:
- amd64
- 386
- arm
- arm64
goarm:
- 6
- 7
archives:
-
replacements:
'386': i386
darwin: Darwin
linux: Linux
windows: Windows
amd64: x86_64
checksum:
name_template: checksums.txt
snapshot:
name_template: '{{ .Tag }}-next'
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
brews:
-
name: 'pkger'
github:
owner: 'markbates'
name: 'homebrew-tap'
install: |
bin.install "pkger"

View File

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2019 Mark Bates
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,54 +0,0 @@
TAGS ?= ""
GO_BIN ?= "go"
install: tidy
cd ./cmd/pkger && $(GO_BIN) install -tags ${TAGS} -v .
make tidy
run: install
cd ./examples/app; pkger
tidy:
$(GO_BIN) mod tidy -v
build: tidy
$(GO_BIN) build -v .
make tidy
test: tidy
$(GO_BIN) test -count 1 -cover -tags ${TAGS} -timeout 1m ./...
make tidy
cov:
$(GO_BIN) test -coverprofile cover.out -tags ${TAGS} ./...
go tool cover -html cover.out
make tidy
ci-test:
$(GO_BIN) test -tags ${TAGS} -race ./...
lint:
go get github.com/golangci/golangci-lint/cmd/golangci-lint
golangci-lint run --enable-all
make tidy
update:
rm go.*
$(GO_BIN) mod init
$(GO_BIN) mod tidy
make test
make install
make tidy
release-test:
$(GO_BIN) test -tags ${TAGS} -race ./...
make tidy
release:
$(GO_BIN) get github.com/gobuffalo/release
make tidy
release -y -f version.go --skip-packr
make tidy

View File

@ -1,431 +0,0 @@
# Pkger
[`github.com/markbates/pkger`](https://godoc.org/github.com/markbates/pkger) is a tool for embedding static files into Go binaries. It will, hopefully, be a replacement for [`github.com/gobuffalo/packr/v2`](https://godoc.org/github.com/gobuffalo/packr/v2).
### Requirements
* Go 1.13+
* Go Modules
## How it Works (Module Aware Pathing)
Pkger is powered by the dark magic of Go Modules, so they're like, totally required.
With Go Modules pkger can resolve packages with accuracy. No more guessing and trying to
figure out build paths, GOPATHS, etc... for this tired old lad.
With the module's path correctly resolved, it can serve as the "root" directory for that
module, and all files in that module's directory are available.
Paths:
* Paths should use UNIX style paths:
`/cmd/pkger/main.go`
* If unspecified the path's package is assumed to be the current module.
* Packages can specified in at the beginning of a path with a `:` seperator.
github.com/markbates/pkger:/cmd/pkger/main.go
* There are no relative paths. All paths are absolute to the modules root.
```
"github.com/gobuffalo/buffalo:/go.mod" => $GOPATH/pkg/mod/github.com/gobuffalo/buffalo@v0.14.7/go.mod
```
## CLI
### Installation
```bash
$ go get github.com/markbates/pkger/cmd/pkger
$ pkger -h
```
### Usage
```bash
$ pkger
```
The result will be a `pkged.go` file in the **root** of the module with the embedded information and the package name of the module.
```go
// ./pkged.go
package <.>
// Pkger stuff here
```
The `-o` flag can be used to specify the directory of the `pkged.go` file.
```bash
$ pkger -o cmd/reader
```
The result will be a `pkged.go` file in the **cmd/reader** folder with the embedded information and the package name of that folder.
```go
// cmd/reader/pkged.go
package <reader>
// Pkger stuff here
```
### Including Files at Package Time
There may be reasons where you don't reference a particular file, or folder, that you want embedded in your application, such as a build artifact.
To do this you may use either the [`github.com/markbates/pkger#Include`](https://godoc.org/github.com/markbates/pkger#Include) function to set a no-op parser directive to include the specified path.
Alternatively, you may use the `-include` flag with the `pkger` and `pkger list` commands.
```bash
$ pkger list -include /actions -include github.com/gobuffalo/buffalo:/app.go
app
> app:/actions
> app:/actions/actions.go
> app:/assets
> app:/assets/css
> app:/assets/css/_buffalo.scss
> app:/assets/css/application.scss
> app:/assets/images
> app:/assets/images/favicon.ico
> app:/assets/images/logo.svg
> app:/assets/js
> app:/assets/js/application.js
> app:/go.mod
> app:/locales/all.en-us.yaml
> app:/public
> app:/public/assets
> app:/public/assets/.keep
> app:/public/assets/app.css
> app:/public/images
> app:/public/images/img1.png
> app:/public/index.html
> app:/public/robots.txt
> app:/templates
> app:/templates/_flash.plush.html
> app:/templates/application.plush.html
> app:/templates/index.plush.html
> app:/web
> app:/web/web.go
> github.com/gobuffalo/buffalo:/app.go
> github.com/gobuffalo/buffalo:/logo.svg
```
## Reference Application
The reference application for the `README` examples, as well as all testing, can be found at [https://github.com/markbates/pkger/tree/master/pkging/pkgtest/testdata/ref](https://github.com/markbates/pkger/tree/master/pkging/pkgtest/testdata/ref).
```
├── actions
│   └── actions.go
├── assets
│   ├── css
│   │   ├── _buffalo.scss
│   │   └── application.scss
│   ├── images
│   │   ├── favicon.ico
│   │   └── logo.svg
│   └── js
│   └── application.js
├── go.mod
├── go.sum
├── locales
│   └── all.en-us.yaml
├── main.go
├── mod
│   └── mod.go
├── models
│   └── models.go
├── public
│   ├── assets
│   │   └── app.css
│   ├── images
│   │   └── img1.png
│   ├── index.html
│   └── robots.txt
├── templates
│   ├── _flash.plush.html
│   ├── application.plush.html
│   └── index.plush.html
└── web
└── web.go
13 directories, 20 files
```
## API Usage
Pkger's API is modeled on that of the [`os`](https://godoc.org/os) package in Go's standard library. This makes Pkger usage familiar to Go developers.
The two most important interfaces are [`github.com/markbates/pkger/pkging#Pkger`](https://godoc.org/github.com/markbates/pkger/pkging#Pkger) and [`github.com/markbates/pkger/pkging#File`](https://godoc.org/github.com/markbates/pkger/pkging#File).
```go
type Pkger interface {
Parse(p string) (Path, error)
Current() (here.Info, error)
Info(p string) (here.Info, error)
Create(name string) (File, error)
MkdirAll(p string, perm os.FileMode) error
Open(name string) (File, error)
Stat(name string) (os.FileInfo, error)
Walk(p string, wf filepath.WalkFunc) error
Remove(name string) error
RemoveAll(path string) error
}
type File interface {
Close() error
Info() here.Info
Name() string
Open(name string) (http.File, error)
Path() Path
Read(p []byte) (int, error)
Readdir(count int) ([]os.FileInfo, error)
Seek(offset int64, whence int) (int64, error)
Stat() (os.FileInfo, error)
Write(b []byte) (int, error)
}
```
These two interfaces, along with the [`os#FileInfo`](https://godoc.org/os#FileInfo), provide the bulk of the API surface area.
### Open
```go
func run() error {
f, err := pkger.Open("/public/index.html")
if err != nil {
return err
}
defer f.Close()
info, err := f.Stat()
if err != nil {
return err
}
fmt.Println("Name: ", info.Name())
fmt.Println("Size: ", info.Size())
fmt.Println("Mode: ", info.Mode())
fmt.Println("ModTime: ", info.ModTime())
if _, err := io.Copy(os.Stdout, f); err != nil {
return err
}
return nil
}
```
### Stat
```go
func run() error {
info, err := pkger.Stat("/public/index.html")
if err != nil {
return err
}
fmt.Println("Name: ", info.Name())
fmt.Println("Size: ", info.Size())
fmt.Println("Mode: ", info.Mode())
fmt.Println("ModTime: ", info.ModTime())
return nil
}
```
### Walk
```go
func run() error {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 0, ' ', tabwriter.Debug)
defer w.Flush()
return pkger.Walk("/public", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
fmt.Fprintf(w,
"%s \t %d \t %s \t %s \t\n",
info.Name(),
info.Size(),
info.Mode(),
info.ModTime().Format(time.RFC3339),
)
return nil
})
}
```
## Understanding the Parser
The [`github.com/markbates/pkger/parser#Parser`](https://godoc.org/github.com/markbates/pkger/parser#Parser) works by statically analyzing the source code of your module using the [`go/parser`](https://godoc.org/go/parser) to find a selection of declarations.
The following declarations in your source code will tell the parser to embed files or folders.
* `pkger.Dir("<path>")` - Embeds all files under the specified path.
* `pkger.Open("<path>")` - Embeds the file, or folder, of the specified path.
* `pkger.Stat("<path>")` - Embeds the file, or folder, of the specified path.
* `pkger.Walk("<path>", filepath.WalkFunc)` - Embeds all files under the specified path.
* `pkger.Include("<path>")` - `Include` is a no-op that directs the pkger tool to include the desired file or folder.
### CLI Usage
To see what declarations the parser has found, you can use the `pkger parse` command to get a `JSON` list of the declarations.
```bash
$ pkger parse
{
".": [
{
"file": {
"Abs": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/foo/bar/baz",
"Path": {
"Pkg": "app",
"Name": "/foo/bar/baz"
},
"Here": {
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
"ImportPath": "app",
"Module": {
"Path": "app",
"Main": true,
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
"GoMod": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/go.mod",
"GoVersion": "1.13"
},
"Name": "main"
}
},
"pos": {
"Filename": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/main.go",
"Offset": 629,
"Line": 47,
"Column": 27
},
"type": "pkger.MkdirAll",
"value": "/foo/bar/baz"
},
{
"file": {
"Abs": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/foo/bar/baz/biz.txt",
"Path": {
"Pkg": "app",
"Name": "/foo/bar/baz/biz.txt"
},
"Here": {
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
"ImportPath": "app",
"Module": {
"Path": "app",
"Main": true,
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
"GoMod": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/go.mod",
"GoVersion": "1.13"
},
"Name": "main"
}
},
"pos": {
"Filename": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/main.go",
"Offset": 706,
"Line": 51,
"Column": 25
},
"type": "pkger.Create",
"value": "/foo/bar/baz/biz.txt"
},
...
]
}
```
For a module aware list use the `pkger list` command.
```bash
$ pkger list
app
> app:/assets
> app:/assets/css
> app:/assets/css/_buffalo.scss
> app:/assets/css/application.scss
> app:/assets/images
> app:/assets/images/favicon.ico
> app:/assets/images/logo.svg
> app:/assets/js
> app:/assets/js/application.js
> app:/go.mod
> app:/locales/all.en-us.yaml
> app:/public
> app:/public/assets
> app:/public/assets/.keep
> app:/public/assets/app.css
> app:/public/images
> app:/public/images/img1.png
> app:/public/index.html
> app:/public/robots.txt
> app:/templates
> app:/templates/_flash.plush.html
> app:/templates/application.plush.html
> app:/templates/index.plush.html
> app:/web
> app:/web/web.go
> github.com/gobuffalo/buffalo:/logo.svg
```
The `-json` flag can be used to get a more detailed list in JSON.
```bash
$ pkger list -json
{
"ImportPath": "app",
"Files": [
{
"Abs": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/assets",
"Path": {
"Pkg": "app",
"Name": "/assets"
},
"Here": {
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/assets",
"ImportPath": "",
"Module": {
"Path": "app",
"Main": true,
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
"GoMod": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/go.mod",
"GoVersion": "1.13"
},
"Name": "assets"
}
},
{
"Abs": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/assets/css",
"Path": {
"Pkg": "app",
"Name": "/assets/css"
},
"Here": {
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/assets",
"ImportPath": "",
"Module": {
"Path": "app",
"Main": true,
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
"GoMod": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/go.mod",
"GoVersion": "1.13"
},
"Name": "assets"
}
},
...
}
```

View File

@ -1,24 +0,0 @@
# github.com/markbates/pkger Stands on the Shoulders of Giants
github.com/markbates/pkger 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.
Thank you to the following **GIANTS**:
* [github.com/davecgh/go-spew](https://godoc.org/github.com/davecgh/go-spew)
* [github.com/kr/pretty](https://godoc.org/github.com/kr/pretty)
* [github.com/kr/pty](https://godoc.org/github.com/kr/pty)
* [github.com/kr/text](https://godoc.org/github.com/kr/text)
* [github.com/pmezard/go-difflib](https://godoc.org/github.com/pmezard/go-difflib)
* [github.com/stretchr/objx](https://godoc.org/github.com/stretchr/objx)
* [github.com/stretchr/testify](https://godoc.org/github.com/stretchr/testify)
* [gopkg.in/check.v1](https://godoc.org/gopkg.in/check.v1)
* [gopkg.in/yaml.v2](https://godoc.org/gopkg.in/yaml.v2)

View File

@ -1,19 +0,0 @@
package pkger
import (
"github.com/markbates/pkger/pkging"
)
// Apply will wrap the current implementation
// of pkger.Pkger with the new pkg. This allows
// for layering of pkging.Pkger implementations.
func Apply(pkg pkging.Pkger, err error) error {
if err != nil {
panic(err)
return err
}
gil.Lock()
defer gil.Unlock()
current = pkging.Wrap(current, pkg)
return nil
}

View File

@ -1,8 +0,0 @@
module github.com/markbates/pkger
go 1.13
require (
github.com/gobuffalo/here v0.6.0
github.com/stretchr/testify v1.4.0
)

View File

@ -1,22 +0,0 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gobuffalo/here v0.6.0 h1:hYrd0a6gDmWxBM4TnrGw8mQg24iSVoIkHEk7FodQcBI=
github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View File

@ -1,14 +0,0 @@
package here
import (
"github.com/gobuffalo/here"
)
type Info = here.Info
type Module = here.Module
type Path = here.Path
var Here = here.New()
var Dir = Here.Dir
var Package = Here.Package
var Current = Here.Current

View File

@ -1,124 +0,0 @@
// Code generated by github.com/gobuffalo/mapgen. DO NOT EDIT.
package maps
import (
"encoding/json"
"fmt"
"sort"
"sync"
"github.com/markbates/pkger/here"
"github.com/markbates/pkger/pkging"
)
// Files wraps sync.Map and uses the following types:
// key: here.Path
// value: pkging.File
type Files struct {
data *sync.Map
once *sync.Once
}
func (m *Files) Data() *sync.Map {
if m.once == nil {
m.once = &sync.Once{}
}
m.once.Do(func() {
if m.data == nil {
m.data = &sync.Map{}
}
})
return m.data
}
func (m *Files) MarshalJSON() ([]byte, error) {
var err error
mm := map[string]interface{}{}
m.Data().Range(func(key, value interface{}) bool {
var b []byte
b, err = json.Marshal(key)
if err != nil {
return false
}
mm[string(b)] = value
return true
})
if err != nil {
return nil, err
}
return json.Marshal(mm)
}
func (m *Files) UnmarshalJSON(b []byte) error {
mm := map[string]pkging.File{}
if err := json.Unmarshal(b, &mm); err != nil {
return err
}
for k, v := range mm {
var pt here.Path
if err := json.Unmarshal([]byte(k), &pt); err != nil {
return err
}
m.Store(pt, v)
}
return nil
}
// Delete the key from the map
func (m *Files) Delete(key here.Path) {
m.Data().Delete(key)
}
// Load the key from the map.
// Returns pkging.File or bool.
// A false return indicates either the key was not found
// or the value is not of type pkging.File
func (m *Files) Load(key here.Path) (pkging.File, bool) {
i, ok := m.Data().Load(key)
if !ok {
return nil, false
}
s, ok := i.(pkging.File)
return s, ok
}
// Range over the pkging.File values in the map
func (m *Files) Range(f func(key here.Path, value pkging.File) bool) {
m.Data().Range(func(k, v interface{}) bool {
key, ok := k.(here.Path)
if !ok {
return false
}
value, ok := v.(pkging.File)
if !ok {
return false
}
return f(key, value)
})
}
// Store a pkging.File in the map
func (m *Files) Store(key here.Path, value pkging.File) {
m.Data().Store(key, value)
}
// Keys returns a list of keys in the map
func (m *Files) Keys() []here.Path {
var keys []here.Path
m.Range(func(key here.Path, value pkging.File) bool {
keys = append(keys, key)
return true
})
sort.Slice(keys, func(a, b int) bool {
return keys[a].String() <= keys[b].String()
})
return keys
}
func (m *Files) String() string {
return fmt.Sprintf("%v", m.Keys())
}

View File

@ -1,103 +0,0 @@
// Code generated by github.com/markbates/pkger/mapgen. DO NOT EDIT.
package maps
import (
"encoding/json"
"fmt"
"sort"
"sync"
"github.com/markbates/pkger/here"
)
// Infos wraps sync.Map and uses the following types:
// key: string
// value: here.Info
type Infos struct {
data *sync.Map
once *sync.Once
}
func (m *Infos) Data() *sync.Map {
if m.once == nil {
m.once = &sync.Once{}
}
m.once.Do(func() {
if m.data == nil {
m.data = &sync.Map{}
}
})
return m.data
}
func (m *Infos) MarshalJSON() ([]byte, error) {
mm := map[string]interface{}{}
m.data.Range(func(key, value interface{}) bool {
mm[fmt.Sprintf("%s", key)] = value
return true
})
return json.Marshal(mm)
}
func (m *Infos) UnmarshalJSON(b []byte) error {
mm := map[string]here.Info{}
if err := json.Unmarshal(b, &mm); err != nil {
return err
}
for k, v := range mm {
m.Store(k, v)
}
return nil
}
// Delete the key from the map
func (m *Infos) Delete(key string) {
m.Data().Delete(key)
}
// Load the key from the map.
// Returns here.Info or bool.
// A false return indicates either the key was not found
// or the value is not of type here.Info
func (m *Infos) Load(key string) (here.Info, bool) {
m.Data()
i, ok := m.data.Load(key)
if !ok {
return here.Info{}, false
}
s, ok := i.(here.Info)
return s, ok
}
// Range over the here.Info values in the map
func (m *Infos) Range(f func(key string, value here.Info) bool) {
m.Data().Range(func(k, v interface{}) bool {
key, ok := k.(string)
if !ok {
return false
}
value, ok := v.(here.Info)
if !ok {
return false
}
return f(key, value)
})
}
// Store a here.Info in the map
func (m *Infos) Store(key string, value here.Info) {
m.Data().Store(key, value)
}
// Keys returns a list of keys in the map
func (m *Infos) Keys() []string {
var keys []string
m.Range(func(key string, value here.Info) bool {
keys = append(keys, key)
return true
})
sort.Strings(keys)
return keys
}

View File

@ -1,95 +0,0 @@
package pkger
import (
"net/http"
"os"
"path/filepath"
"sync"
"github.com/markbates/pkger/here"
"github.com/markbates/pkger/pkging"
"github.com/markbates/pkger/pkging/stdos"
)
var current pkging.Pkger
var gil = &sync.RWMutex{}
var disk = func() pkging.Pkger {
her, _ := here.Current()
n, _ := stdos.New(her)
return n
}()
func impl() pkging.Pkger {
gil.RLock()
defer gil.RUnlock()
if current == nil {
return disk
}
return current
}
type Dir string
func (d Dir) Open(name string) (http.File, error) {
f, err := impl().Open(string(d))
if err != nil {
return nil, err
}
return f.Open(name)
}
// Parse the string in here.Path format.
func Parse(p string) (here.Path, error) {
return impl().Parse(p)
}
// Current returns the here.Info representing the current Pkger implementation.
func Current() (here.Info, error) {
return impl().Current()
}
// Info returns the here.Info of the here.Path
func Info(p string) (here.Info, error) {
return impl().Info(p)
}
// Create creates the named file with mode 0666 (before umask) - It's actually 0644, truncating it if it already exists. If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR.
func Create(p string) (pkging.File, error) {
return impl().Create(p)
}
// MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.
func MkdirAll(p string, perm os.FileMode) error {
return impl().MkdirAll(p, perm)
}
// Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY.
func Open(p string) (pkging.File, error) {
return impl().Open(p)
}
// Stat returns a FileInfo describing the named file.
func Stat(name string) (os.FileInfo, error) {
return impl().Stat(name)
}
// Walk walks the file tree rooted at root, calling walkFn for each file or directory in the tree, including root. All errors that arise visiting files and directories are filtered by walkFn. The files are walked in lexical order, which makes the output deterministic but means that for very large directories Walk can be inefficient. Walk does not follow symbolic links. - That is from the standard library. I know. Their grammar teachers can not be happy with them right now.
func Walk(p string, wf filepath.WalkFunc) error {
return impl().Walk(p, wf)
}
// Remove removes the named file or (empty) directory.
func Remove(name string) error {
return impl().Remove(name)
}
// RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error).
func RemoveAll(name string) error {
return impl().RemoveAll(name)
}
// Include is a no-op that directs the pkger tool to include the desired file or folder.
func Include(name string) string {
return name
}

View File

@ -1,7 +0,0 @@
package pkging
import "os"
type Adder interface {
Add(files ...*os.File) error
}

View File

@ -1,44 +0,0 @@
package pkging
import (
"net/http"
"os"
"github.com/markbates/pkger/here"
)
type File interface {
// Close closes the File, rendering it unusable for I/O.
Close() error
// Info returns the here.Info of the file
Info() here.Info
// Name retuns the name of the file
Name() string
// Open implements the http.FileSystem interface. A FileSystem implements access to a collection of named files. The elements in a file path are separated by slash ('/', U+002F) characters, regardless of host operating system convention.
Open(name string) (http.File, error)
// Path returns the here.Path of the file
Path() here.Path
// Read reads up to len(b) bytes from the File. It returns the number of bytes read and any error encountered. At end of file, Read returns 0, io.EOF.
Read(p []byte) (int, error)
// Readdir reads the contents of the directory associated with file and returns a slice of up to n FileInfo values, as would be returned by Lstat, in directory order. Subsequent calls on the same file will yield further FileInfos.
//
// If n > 0, Readdir returns at most n FileInfo structures. In this case, if Readdir returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is io.EOF.
//
// If n <= 0, Readdir returns all the FileInfo from the directory in a single slice. In this case, if Readdir succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, Readdir returns the FileInfo read until that point and a non-nil error.
Readdir(count int) ([]os.FileInfo, error)
// Seek sets the offset for the next Read or Write on file to offset, interpreted according to whence: 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end. It returns the new offset and an error, if any.
Seek(offset int64, whence int) (int64, error)
// Stat returns the FileInfo structure describing file. If there is an error, it will be of type *PathError.
Stat() (os.FileInfo, error)
// Write writes len(b) bytes to the File. It returns the number of bytes written and an error, if any. Write returns a non-nil error when n != len(b).
Write(b []byte) (int, error)
}

View File

@ -1,65 +0,0 @@
package pkging
import (
"encoding/json"
"os"
"time"
)
type Details struct {
Name string `json:"name"`
Size int64 `json:"size"`
Mode os.FileMode `json:"mode"`
ModTime ModTime `json:"mod_time"`
IsDir bool `json:"is_dir"`
Sys interface{} `json:"sys"`
}
type FileInfo struct {
Details `json:"details"`
}
func (f *FileInfo) String() string {
b, _ := json.MarshalIndent(f, "", " ")
return string(b)
}
func (f *FileInfo) Name() string {
return f.Details.Name
}
func (f *FileInfo) Size() int64 {
return f.Details.Size
}
func (f *FileInfo) Mode() os.FileMode {
return f.Details.Mode
}
func (f *FileInfo) ModTime() time.Time {
return time.Time(f.Details.ModTime)
}
func (f *FileInfo) IsDir() bool {
return f.Details.IsDir
}
func (f *FileInfo) Sys() interface{} {
return f.Details.Sys
}
var _ os.FileInfo = &FileInfo{}
func NewFileInfo(info os.FileInfo) *FileInfo {
fi := &FileInfo{
Details: Details{
Name: info.Name(),
Size: info.Size(),
Mode: info.Mode(),
ModTime: ModTime(info.ModTime()),
IsDir: info.IsDir(),
Sys: info.Sys(),
},
}
return fi
}

View File

@ -1,24 +0,0 @@
package pkging
import (
"encoding/json"
"time"
)
const timeFmt = time.RFC3339Nano
type ModTime time.Time
func (m ModTime) MarshalJSON() ([]byte, error) {
t := time.Time(m)
return json.Marshal(t.Format(timeFmt))
}
func (m *ModTime) UnmarshalJSON(b []byte) error {
t := time.Time{}
if err := json.Unmarshal(b, &t); err != nil {
return err
}
(*m) = ModTime(t)
return nil
}

View File

@ -1,43 +0,0 @@
package pkging
import (
"os"
"path/filepath"
"github.com/markbates/pkger/here"
)
type Pkger interface {
// Parse the string in here.Path format.
Parse(p string) (here.Path, error)
// Current returns the here.Info representing the current Pkger implementation.
Current() (here.Info, error)
// Info returns the here.Info of the here.Path
Info(p string) (here.Info, error)
// Create creates the named file with mode 0666 (before umask) - It's actually 0644, truncating it if it already exists. If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR.
Create(name string) (File, error)
// MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.
MkdirAll(p string, perm os.FileMode) error
// Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY.
// @Parser Directive
Open(name string) (File, error)
// Stat returns a FileInfo describing the named file.
// @Parser Directive
Stat(name string) (os.FileInfo, error)
// Walk walks the file tree rooted at root, calling walkFn for each file or directory in the tree, including root. All errors that arise visiting files and directories are filtered by walkFn. The files are walked in lexical order, which makes the output deterministic but means that for very large directories Walk can be inefficient. Walk does not follow symbolic links. - That is from the standard library. I know. Their grammar teachers can not be happy with them right now.
// @Parser Directive
Walk(p string, wf filepath.WalkFunc) error
// Remove removes the named file or (empty) directory.
Remove(name string) error
// RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error).
RemoveAll(path string) error
}

View File

@ -1,73 +0,0 @@
package stdos
import (
"net/http"
"os"
"path"
"github.com/markbates/pkger/here"
"github.com/markbates/pkger/pkging"
)
var _ pkging.File = &File{}
type File struct {
*os.File
info *pkging.FileInfo
her here.Info
path here.Path
pkging pkging.Pkger
}
// Close closes the File, rendering it unusable for I/O.
func (f *File) Close() error {
return f.File.Close()
}
// Info returns the here.Info of the file
func (f *File) Info() here.Info {
return f.her
}
// Name retuns the name of the file in pkger format
func (f File) Name() string {
return f.path.String()
}
// Readdir reads the contents of the directory associated with file and returns a slice of up to n FileInfo values, as would be returned by Lstat, in directory order. Subsequent calls on the same file will yield further FileInfos.
//
// If n > 0, Readdir returns at most n FileInfo structures. In this case, if Readdir returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is io.EOF.
//
// If n <= 0, Readdir returns all the FileInfo from the directory in a single slice. In this case, if Readdir succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, Readdir returns the FileInfo read until that point and a non-nil error.
func (f *File) Readdir(count int) ([]os.FileInfo, error) {
return f.File.Readdir(count)
}
// Open implements the http.FileSystem interface. A FileSystem implements access to a collection of named files. The elements in a file path are separated by slash ('/', U+002F) characters, regardless of host operating system convention.
func (f *File) Open(name string) (http.File, error) {
fp := path.Join(f.Path().Name, name)
f2, err := f.pkging.Open(fp)
if err != nil {
return nil, err
}
return f2, nil
}
// Path returns the here.Path of the file
func (f *File) Path() here.Path {
return f.path
}
// Stat returns the FileInfo structure describing file. If there is an error, it will be of type *PathError.
func (f *File) Stat() (os.FileInfo, error) {
if f.info != nil {
return f.info, nil
}
info, err := f.File.Stat()
if err != nil {
return nil, err
}
f.info = pkging.NewFileInfo(info)
return f.info, nil
}

View File

@ -1 +0,0 @@
package stdos

View File

@ -1,223 +0,0 @@
package stdos
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/markbates/pkger/here"
"github.com/markbates/pkger/internal/maps"
"github.com/markbates/pkger/pkging"
)
var _ pkging.Pkger = &Pkger{}
type Pkger struct {
Here here.Info
infos *maps.Infos
}
// New returns *Pkger for the provided here.Info
func New(her here.Info) (*Pkger, error) {
p := &Pkger{
infos: &maps.Infos{},
Here: her,
}
p.infos.Store(her.ImportPath, her)
return p, nil
}
// Create creates the named file with mode 0666 (before umask) - It's actually 0644, truncating it if it already exists. If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR.
func (fx *Pkger) Create(name string) (pkging.File, error) {
pt, err := fx.Parse(name)
if err != nil {
return nil, err
}
her, err := fx.Info(pt.Pkg)
if err != nil {
return nil, err
}
name = filepath.Join(her.Dir, pt.Name)
f, err := os.Create(name)
if err != nil {
return nil, err
}
nf := &File{
File: f,
her: her,
path: pt,
pkging: fx,
}
info, err := f.Stat()
if err != nil {
return nil, err
}
nf.info = pkging.NewFileInfo(info)
return nf, nil
}
// Current returns the here.Info representing the current Pkger implementation.
func (f *Pkger) Current() (here.Info, error) {
return f.Here, nil
}
// Info returns the here.Info of the here.Path
func (f *Pkger) Info(p string) (here.Info, error) {
info, ok := f.infos.Load(p)
if ok {
return info, nil
}
info, err := here.Package(p)
if err != nil {
return info, err
}
f.infos.Store(p, info)
return info, nil
}
// MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.
func (f *Pkger) MkdirAll(p string, perm os.FileMode) error {
pt, err := f.Parse(p)
if err != nil {
return err
}
info, err := f.Info(pt.Pkg)
if err != nil {
return err
}
return os.MkdirAll(filepath.Join(info.Dir, p), perm)
}
// Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY.
func (fx *Pkger) Open(name string) (pkging.File, error) {
pt, err := fx.Parse(name)
if err != nil {
return nil, err
}
her, err := fx.Info(pt.Pkg)
if err != nil {
return nil, err
}
name = filepath.Join(her.Dir, pt.Name)
f, err := os.Open(name)
if err != nil {
return nil, err
}
nf := &File{
File: f,
her: her,
path: pt,
pkging: fx,
}
info, err := f.Stat()
if err != nil {
return nil, err
}
nf.info = pkging.NewFileInfo(info)
return nf, nil
}
// Parse the string in here.Path format.
func (f *Pkger) Parse(p string) (here.Path, error) {
return f.Here.Parse(p)
}
// Stat returns a FileInfo describing the named file.
func (fx *Pkger) Stat(name string) (os.FileInfo, error) {
pt, err := fx.Parse(name)
if err != nil {
return nil, err
}
her, err := fx.Info(pt.Pkg)
if err != nil {
return nil, err
}
info, err := os.Stat(filepath.Join(her.Dir, pt.Name))
if err != nil {
return nil, err
}
info = pkging.NewFileInfo(info)
return info, nil
}
// Walk walks the file tree rooted at root, calling walkFn for each file or directory in the tree, including root. All errors that arise visiting files and directories are filtered by walkFn. The files are walked in lexical order, which makes the output deterministic but means that for very large directories Walk can be inefficient. Walk does not follow symbolic links. - That is from the standard library. I know. Their grammar teachers can not be happy with them right now.
func (f *Pkger) Walk(p string, wf filepath.WalkFunc) error {
pt, err := f.Parse(p)
if err != nil {
return err
}
info, err := f.Info(pt.Pkg)
if err != nil {
return err
}
fp := filepath.Join(info.Dir, pt.Name)
err = filepath.Walk(fp, func(path string, fi os.FileInfo, err error) error {
if err != nil {
return err
}
pt, err := f.Parse(fmt.Sprintf("%s:%s", pt.Pkg, path))
if err != nil {
return err
}
info, err := f.Info(pt.Pkg)
if err != nil {
return err
}
path = strings.TrimPrefix(path, info.Dir)
path = strings.ReplaceAll(path, "\\", "/")
pt.Name = path
return wf(pt.String(), pkging.NewFileInfo(fi), nil)
})
return err
}
// Remove removes the named file or (empty) directory.
func (fx *Pkger) Remove(name string) error {
pt, err := fx.Parse(name)
if err != nil {
return err
}
info, err := fx.Info(pt.Pkg)
if err != nil {
return err
}
return os.Remove(filepath.Join(info.Dir, pt.Name))
}
// RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error).
func (fx *Pkger) RemoveAll(name string) error {
pt, err := fx.Parse(name)
if err != nil {
return err
}
info, err := fx.Info(pt.Pkg)
if err != nil {
return err
}
return os.RemoveAll(filepath.Join(info.Dir, pt.Name))
}

View File

@ -1,145 +0,0 @@
package pkging
import (
"fmt"
"os"
"path/filepath"
"github.com/markbates/pkger/here"
)
func Wrap(parent, with Pkger) Pkger {
return withPkger{
base: with,
parent: parent,
}
}
type withPkger struct {
base Pkger
parent Pkger
}
func (w withPkger) String() string {
if w.parent == nil {
return fmt.Sprintf("%T", w.base)
}
return fmt.Sprintf("%T > %T", w.base, w.parent)
}
func (w withPkger) Parse(p string) (here.Path, error) {
pt, err := w.base.Parse(p)
if err != nil {
if w.parent != nil {
return w.parent.Parse(p)
}
return pt, err
}
return pt, nil
}
func (w withPkger) Current() (here.Info, error) {
pt, err := w.base.Current()
if err != nil {
if w.parent != nil {
return w.parent.Current()
}
return pt, err
}
return pt, nil
}
func (w withPkger) Info(p string) (here.Info, error) {
pt, err := w.base.Info(p)
if err != nil {
if w.parent != nil {
return w.parent.Info(p)
}
return pt, err
}
return pt, nil
}
// Create creates the named file with mode 0666 (before umask) - It's actually 0644, truncating it if it already exists. If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR.
func (w withPkger) Create(p string) (File, error) {
pt, err := w.base.Create(p)
if err != nil {
if w.parent != nil {
return w.parent.Create(p)
}
return pt, err
}
return pt, nil
}
// MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.
func (w withPkger) MkdirAll(p string, perm os.FileMode) error {
err := w.base.MkdirAll(p, perm)
if err != nil {
return err
}
if w.parent != nil {
return w.parent.MkdirAll(p, perm)
}
return nil
}
// Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY.
func (w withPkger) Open(p string) (File, error) {
pt, err := w.base.Open(p)
if err != nil {
if w.parent != nil {
return w.parent.Open(p)
}
return pt, err
}
return pt, nil
}
// Stat returns a FileInfo describing the named file.
func (w withPkger) Stat(p string) (os.FileInfo, error) {
pt, err := w.base.Stat(p)
if err != nil {
if w.parent != nil {
return w.parent.Stat(p)
}
return pt, err
}
return pt, nil
}
// Walk walks the file tree rooted at root, calling walkFn for each file or directory in the tree, including root. All errors that arise visiting files and directories are filtered by walkFn. The files are walked in lexical order, which makes the output deterministic but means that for very large directories Walk can be inefficient. Walk does not follow symbolic links. - That is from the standard library. I know. Their grammar teachers can not be happy with them right now.
func (w withPkger) Walk(p string, wf filepath.WalkFunc) error {
err := w.base.Walk(p, wf)
if err != nil {
return err
}
if w.parent != nil {
return w.parent.Walk(p, wf)
}
return nil
}
// Remove removes the named file or (empty) directory.
func (w withPkger) Remove(p string) error {
err := w.base.Remove(p)
if err != nil {
return err
}
if w.parent != nil {
return w.parent.Remove(p)
}
return nil
}
// RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error).
func (w withPkger) RemoveAll(p string) error {
err := w.base.RemoveAll(p)
if err != nil {
return err
}
if w.parent != nil {
return w.parent.RemoveAll(p)
}
return nil
}

View File

@ -1,4 +0,0 @@
package pkger
// Version of pkger
var Version = "development"

13
vendor/modules.txt vendored
View File

@ -1,7 +1,5 @@
# github.com/dgrijalva/jwt-go v3.2.0+incompatible # github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/dgrijalva/jwt-go github.com/dgrijalva/jwt-go
# github.com/gobuffalo/here v0.6.0
github.com/gobuffalo/here
# github.com/gobuffalo/logger v1.0.3 # github.com/gobuffalo/logger v1.0.3
github.com/gobuffalo/logger github.com/gobuffalo/logger
# github.com/gobuffalo/packd v1.0.0 # github.com/gobuffalo/packd v1.0.0
@ -28,8 +26,6 @@ github.com/inconshreveable/mousetrap
github.com/karrick/godirwalk github.com/karrick/godirwalk
# github.com/konsorten/go-windows-terminal-sequences v1.0.3 # github.com/konsorten/go-windows-terminal-sequences v1.0.3
github.com/konsorten/go-windows-terminal-sequences github.com/konsorten/go-windows-terminal-sequences
# github.com/labstack/echo v3.3.10+incompatible
## explicit
# github.com/labstack/echo/v4 v4.1.16 # github.com/labstack/echo/v4 v4.1.16
## explicit ## explicit
github.com/labstack/echo/v4 github.com/labstack/echo/v4
@ -52,13 +48,6 @@ github.com/likexian/whois-parser-go
github.com/markbates/errx github.com/markbates/errx
# github.com/markbates/oncer v1.0.0 # github.com/markbates/oncer v1.0.0
github.com/markbates/oncer github.com/markbates/oncer
# github.com/markbates/pkger v0.16.0
## explicit
github.com/markbates/pkger
github.com/markbates/pkger/here
github.com/markbates/pkger/internal/maps
github.com/markbates/pkger/pkging
github.com/markbates/pkger/pkging/stdos
# github.com/markbates/safe v1.0.1 # github.com/markbates/safe v1.0.1
github.com/markbates/safe github.com/markbates/safe
# github.com/mattn/go-colorable v0.1.6 # github.com/mattn/go-colorable v0.1.6
@ -105,3 +94,5 @@ golang.org/x/text/unicode/bidi
golang.org/x/text/unicode/norm golang.org/x/text/unicode/norm
# golang.org/x/tools v0.0.0-20200308013534-11ec41452d41 # golang.org/x/tools v0.0.0-20200308013534-11ec41452d41
golang.org/x/tools/go/ast/astutil golang.org/x/tools/go/ast/astutil
# gopkg.in/yaml.v2 v2.2.7
## explicit