don't neglect me
201
README.md
|
@ -72,10 +72,6 @@ type File interface {
|
|||
│ │ ├── mark_250px.png
|
||||
│ │ └── mark_400px.png
|
||||
│ └── index.html
|
||||
└── templates
|
||||
├── a.txt
|
||||
└── b
|
||||
└── b.txt
|
||||
```
|
||||
|
||||
```go
|
||||
|
@ -84,69 +80,39 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"github.com/markbates/pkger"
|
||||
)
|
||||
|
||||
const host = ":3000"
|
||||
|
||||
func main() {
|
||||
// get the currently running application's here.Info.
|
||||
// this contains really, really, really useful information
|
||||
// about your application, check it out. :)
|
||||
// we don't need it for this example, but i thought it could
|
||||
// be good to show.
|
||||
current, err := pkger.Current()
|
||||
if err != nil {
|
||||
if err := run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(current)
|
||||
}
|
||||
|
||||
fmt.Printf("Walking files for %s\n", current.ImportPath)
|
||||
// walk the files in this module. "/" is where the `go.mod` for this module is
|
||||
err = pkger.Walk("github.com/gobuffalo/buffalo:/render", func(path string, info os.FileInfo, err error) error {
|
||||
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.Println(">> ", path)
|
||||
|
||||
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
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// find the public directory with using the full pkger path <pkg:/path> to it:
|
||||
// pkg - is the module/package you want to get a file from
|
||||
// if pkg is empty then it is assumed to be current.ImportPath
|
||||
// : - seperator between the module/package name, pkg, and the "file path"
|
||||
// path - this is the ABSOLUTE path to the file/directory you want, as relative
|
||||
// to the root of the module/package's go.mod file.
|
||||
dir, err := pkger.Open("github.com/markbates/pkger/examples/app:/public")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
// don't forget to close the file later
|
||||
defer dir.Close()
|
||||
|
||||
fmt.Printf("\nServing %q on %s\n", dir.Path(), host)
|
||||
|
||||
// serve the public directory on the host (":3000")
|
||||
// just like using the os package you still need to use
|
||||
// http.FileServer to serve a directory.
|
||||
// you DON'T, however, need to use http.Dir all pkger files
|
||||
// already implement that interface.
|
||||
log.Fatal(http.ListenAndServe(host, logger(http.FileServer(dir))))
|
||||
}
|
||||
|
||||
// logger will print out the requests as they come in, otherwise its a blank
|
||||
// screen, and that's no fun.
|
||||
func logger(h http.Handler) http.HandlerFunc {
|
||||
return func(res http.ResponseWriter, req *http.Request) {
|
||||
log.Println(req.Method, req.URL.String())
|
||||
h.ServeHTTP(res, req)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -155,65 +121,13 @@ func logger(h http.Handler) http.HandlerFunc {
|
|||
```bash
|
||||
# compile the go binary as usual and run the app:
|
||||
$ go build -v; ./app
|
||||
|
||||
{
|
||||
"Dir": "$GOPATH/src/github.com/markbates/pkger/examples/app",
|
||||
"ImportPath": "github.com/markbates/pkger/examples/app",
|
||||
"Imports": [
|
||||
"fmt",
|
||||
"github.com/markbates/pkger",
|
||||
"log",
|
||||
"net/http",
|
||||
"os"
|
||||
],
|
||||
"Module": {
|
||||
"Dir": "$GOPATH/src/github.com/markbates/pkger/examples/app",
|
||||
"GoMod": "$GOPATH/src/github.com/markbates/pkger/examples/app/go.mod",
|
||||
"GoVersion": "1.13",
|
||||
"Main": true,
|
||||
"Path": "github.com/markbates/pkger/examples/app"
|
||||
},
|
||||
"Name": "main"
|
||||
}
|
||||
Walking files for github.com/markbates/pkger/examples/app
|
||||
>> github.com/gobuffalo/buffalo:/render
|
||||
>> github.com/gobuffalo/buffalo:/render/auto.go
|
||||
>> github.com/gobuffalo/buffalo:/render/auto_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/download.go
|
||||
>> github.com/gobuffalo/buffalo:/render/download_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/func.go
|
||||
>> github.com/gobuffalo/buffalo:/render/func_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/helpers.go
|
||||
>> github.com/gobuffalo/buffalo:/render/html.go
|
||||
>> github.com/gobuffalo/buffalo:/render/html_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/js.go
|
||||
>> github.com/gobuffalo/buffalo:/render/js_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/json.go
|
||||
>> github.com/gobuffalo/buffalo:/render/json_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/markdown_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/options.go
|
||||
>> github.com/gobuffalo/buffalo:/render/partials_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/plain.go
|
||||
>> github.com/gobuffalo/buffalo:/render/plain_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/render.go
|
||||
>> github.com/gobuffalo/buffalo:/render/render_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/renderer.go
|
||||
>> github.com/gobuffalo/buffalo:/render/sse.go
|
||||
>> github.com/gobuffalo/buffalo:/render/string.go
|
||||
>> github.com/gobuffalo/buffalo:/render/string_map.go
|
||||
>> github.com/gobuffalo/buffalo:/render/string_map_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/string_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/template.go
|
||||
>> github.com/gobuffalo/buffalo:/render/template_engine.go
|
||||
>> github.com/gobuffalo/buffalo:/render/template_helpers.go
|
||||
>> github.com/gobuffalo/buffalo:/render/template_helpers_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/template_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/xml.go
|
||||
>> github.com/gobuffalo/buffalo:/render/xml_test.go
|
||||
|
||||
Serving "github.com/markbates/pkger/examples/app:/public" on :3000
|
||||
2019/09/22 14:07:41 GET /
|
||||
2019/09/22 14:07:41 GET /images/mark.png
|
||||
/public | 128 | drwxr-xr-x | 2019-10-17T15:02:57-04:00 |
|
||||
/public/images | 192 | drwxr-xr-x | 2019-10-17T15:02:57-04:00 |
|
||||
/public/images/mark-small.png | 649549 | -rw-r--r-- | 2019-10-17T15:02:56-04:00 |
|
||||
/public/images/mark.png | 50401191 | -rw-r--r-- | 2019-10-17T15:02:57-04:00 |
|
||||
/public/images/mark_250px.png | 27718 | -rw-r--r-- | 2019-10-17T15:02:57-04:00 |
|
||||
/public/images/mark_400px.png | 63543 | -rw-r--r-- | 2019-10-17T15:02:57-04:00 |
|
||||
/public/index.html | 257 | -rw-r--r-- | 2019-10-17T15:02:57-04:00 |
|
||||
```
|
||||
|
||||
### Output With Packing
|
||||
|
@ -224,62 +138,11 @@ $ pkger
|
|||
|
||||
# compile the go binary as usual and run the app:
|
||||
$ go build -v; ./app
|
||||
{
|
||||
"Dir": "$GOPATH/src/github.com/markbates/pkger/examples/app",
|
||||
"ImportPath": "github.com/markbates/pkger/examples/app",
|
||||
"Imports": [
|
||||
"fmt",
|
||||
"github.com/markbates/pkger",
|
||||
"log",
|
||||
"net/http",
|
||||
"os"
|
||||
],
|
||||
"Module": {
|
||||
"Dir": "$GOPATH/src/github.com/markbates/pkger/examples/app",
|
||||
"GoMod": "$GOPATH/src/github.com/markbates/pkger/examples/app/go.mod",
|
||||
"GoVersion": "1.13",
|
||||
"Main": true,
|
||||
"Path": "github.com/markbates/pkger/examples/app"
|
||||
},
|
||||
"Name": "main"
|
||||
}
|
||||
Walking files for github.com/markbates/pkger/examples/app
|
||||
>> github.com/gobuffalo/buffalo:/render
|
||||
>> github.com/gobuffalo/buffalo:/render/auto.go
|
||||
>> github.com/gobuffalo/buffalo:/render/auto_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/download.go
|
||||
>> github.com/gobuffalo/buffalo:/render/download_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/func.go
|
||||
>> github.com/gobuffalo/buffalo:/render/func_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/helpers.go
|
||||
>> github.com/gobuffalo/buffalo:/render/html.go
|
||||
>> github.com/gobuffalo/buffalo:/render/html_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/js.go
|
||||
>> github.com/gobuffalo/buffalo:/render/js_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/json.go
|
||||
>> github.com/gobuffalo/buffalo:/render/json_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/markdown_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/options.go
|
||||
>> github.com/gobuffalo/buffalo:/render/partials_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/plain.go
|
||||
>> github.com/gobuffalo/buffalo:/render/plain_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/render.go
|
||||
>> github.com/gobuffalo/buffalo:/render/render_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/renderer.go
|
||||
>> github.com/gobuffalo/buffalo:/render/sse.go
|
||||
>> github.com/gobuffalo/buffalo:/render/string.go
|
||||
>> github.com/gobuffalo/buffalo:/render/string_map.go
|
||||
>> github.com/gobuffalo/buffalo:/render/string_map_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/string_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/template.go
|
||||
>> github.com/gobuffalo/buffalo:/render/template_engine.go
|
||||
>> github.com/gobuffalo/buffalo:/render/template_helpers.go
|
||||
>> github.com/gobuffalo/buffalo:/render/template_helpers_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/template_test.go
|
||||
>> github.com/gobuffalo/buffalo:/render/xml.go
|
||||
>> github.com/gobuffalo/buffalo:/render/xml_test.go
|
||||
|
||||
Serving "github.com/markbates/pkger/examples/app:/public" on :3000
|
||||
2019/09/22 14:07:41 GET /
|
||||
2019/09/22 14:07:41 GET /images/mark.png
|
||||
/ | 128 | drwxr-xr-x | 2019-10-17T15:02:57-04:00 |
|
||||
/images | 192 | drwxr-xr-x | 2019-10-17T15:02:57-04:00 |
|
||||
/images/mark-small.png | 649549 | -rw-r--r-- | 2019-10-17T15:02:56-04:00 |
|
||||
/images/mark.png | 50401191 | -rw-r--r-- | 2019-10-17T15:02:57-04:00 |
|
||||
/images/mark_250px.png | 27718 | -rw-r--r-- | 2019-10-17T15:02:57-04:00 |
|
||||
/images/mark_400px.png | 63543 | -rw-r--r-- | 2019-10-17T15:02:57-04:00 |
|
||||
/index.html | 257 | -rw-r--r-- | 2019-10-17T15:02:57-04:00 |
|
||||
```
|
||||
|
|
|
@ -4,6 +4,8 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"github.com/markbates/pkger"
|
||||
)
|
||||
|
@ -15,16 +17,22 @@ func main() {
|
|||
}
|
||||
|
||||
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.Println("Name: ", info.Name())
|
||||
fmt.Println("Size: ", info.Size())
|
||||
fmt.Println("Mode: ", info.Mode())
|
||||
fmt.Println("ModTime: ", info.ModTime())
|
||||
fmt.Println()
|
||||
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
|
||||
})
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -14,16 +16,22 @@ func main() {
|
|||
}
|
||||
|
||||
func run() error {
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 0, ' ', tabwriter.Debug)
|
||||
defer w.Flush()
|
||||
|
||||
return filepath.Walk("./public", func(path string, info os.FileInfo, err error) error {
|
||||
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())
|
||||
fmt.Println()
|
||||
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
|
||||
})
|
||||
|
||||
|
|
5
go.mod
|
@ -3,9 +3,6 @@ module github.com/markbates/pkger
|
|||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
github.com/gobuffalo/buffalo v0.14.11 // indirect
|
||||
github.com/stretchr/testify v1.4.0
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
||||
gopkg.in/yaml.v2 v2.2.4 // indirect
|
||||
)
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
example
|
||||
app
|
||||
pkged.go
|
|
@ -1,7 +0,0 @@
|
|||
FROM alpine
|
||||
|
||||
EXPOSE 3000
|
||||
COPY example /bin/
|
||||
RUN ls -la
|
||||
|
||||
CMD /bin/example
|
|
@ -1,7 +0,0 @@
|
|||
default:
|
||||
cd ../../cmd/pkger && go install -v .
|
||||
pkger -list
|
||||
pkger
|
||||
GOOS=linux go build -v -o example
|
||||
docker build -t pkger:example .
|
||||
docker run -p 3000:3000 pkger:example
|
|
@ -1,10 +0,0 @@
|
|||
module github.com/markbates/pkger/examples/app
|
||||
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/gobuffalo/buffalo v0.14.11 // indirect
|
||||
github.com/markbates/pkger v0.0.0
|
||||
)
|
||||
|
||||
replace github.com/markbates/pkger => ../../../
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/markbates/pkger/pkging/stdos"
|
||||
)
|
||||
|
||||
var DefaultIgnoredFolders = []string{".", "_", "vendor", "node_modules", "_fixtures", "testdata"}
|
||||
// var DefaultIgnoredFolders = []string{".", "_", "vendor", "node_modules", "_fixtures", "testdata"}
|
||||
|
||||
func Parse(her here.Info) ([]here.Path, error) {
|
||||
|
||||
|
|
|
@ -1,94 +1,28 @@
|
|||
package parser
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/markbates/pkger/here"
|
||||
"github.com/markbates/pkger/pkging/pkgtest"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_Parser_App(t *testing.T) {
|
||||
r := require.New(t)
|
||||
|
||||
pwd, err := os.Getwd()
|
||||
info, err := pkgtest.App()
|
||||
r.NoError(err)
|
||||
|
||||
ch := filepath.Join(pwd,
|
||||
"..",
|
||||
"internal",
|
||||
"testdata",
|
||||
"app")
|
||||
|
||||
os.RemoveAll(filepath.Join(ch, "pkged.go"))
|
||||
|
||||
info := here.Info{
|
||||
Dir: ch,
|
||||
ImportPath: "github.com/markbates/pkger/internal/testdata/app",
|
||||
}
|
||||
here.Cache(info.ImportPath, func(s string) (here.Info, error) {
|
||||
return info, nil
|
||||
})
|
||||
|
||||
res, err := Parse(info)
|
||||
|
||||
r.NoError(err)
|
||||
|
||||
sort.Strings(inbed)
|
||||
|
||||
act := make([]string, len(res))
|
||||
for i := 0; i < len(res); i++ {
|
||||
act[i] = res[i].String()
|
||||
}
|
||||
|
||||
sort.Strings(act)
|
||||
r.Equal(inbed, act)
|
||||
}
|
||||
|
||||
var inbed = []string{
|
||||
"github.com/gobuffalo/buffalo:/",
|
||||
"github.com/gobuffalo/buffalo:/render",
|
||||
"github.com/gobuffalo/buffalo:/render/auto.go",
|
||||
"github.com/gobuffalo/buffalo:/render/auto_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/download.go",
|
||||
"github.com/gobuffalo/buffalo:/render/download_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/func.go",
|
||||
"github.com/gobuffalo/buffalo:/render/func_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/helpers.go",
|
||||
"github.com/gobuffalo/buffalo:/render/html.go",
|
||||
"github.com/gobuffalo/buffalo:/render/html_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/js.go",
|
||||
"github.com/gobuffalo/buffalo:/render/js_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/json.go",
|
||||
"github.com/gobuffalo/buffalo:/render/json_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/markdown_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/options.go",
|
||||
"github.com/gobuffalo/buffalo:/render/partials_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/plain.go",
|
||||
"github.com/gobuffalo/buffalo:/render/plain_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/render.go",
|
||||
"github.com/gobuffalo/buffalo:/render/render_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/renderer.go",
|
||||
"github.com/gobuffalo/buffalo:/render/sse.go",
|
||||
"github.com/gobuffalo/buffalo:/render/string.go",
|
||||
"github.com/gobuffalo/buffalo:/render/string_map.go",
|
||||
"github.com/gobuffalo/buffalo:/render/string_map_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/string_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/template.go",
|
||||
"github.com/gobuffalo/buffalo:/render/template_engine.go",
|
||||
"github.com/gobuffalo/buffalo:/render/template_helpers.go",
|
||||
"github.com/gobuffalo/buffalo:/render/template_helpers_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/template_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/xml.go",
|
||||
"github.com/gobuffalo/buffalo:/render/xml_test.go",
|
||||
"github.com/markbates/pkger/internal/testdata/app:/",
|
||||
"github.com/markbates/pkger/internal/testdata/app:/public",
|
||||
"github.com/markbates/pkger/internal/testdata/app:/public/images",
|
||||
"github.com/markbates/pkger/internal/testdata/app:/public/images/mark-small.png",
|
||||
"github.com/markbates/pkger/internal/testdata/app:/public/images/mark.png",
|
||||
"github.com/markbates/pkger/internal/testdata/app:/public/images/mark_250px.png",
|
||||
"github.com/markbates/pkger/internal/testdata/app:/public/images/mark_400px.png",
|
||||
"github.com/markbates/pkger/internal/testdata/app:/public/index.html",
|
||||
r.Equal(pkgtest.AppPaths, act)
|
||||
}
|
||||
|
|
|
@ -79,7 +79,11 @@ func (f *file) findDecals() error {
|
|||
}
|
||||
switch v := vSpec.Values[i].(type) {
|
||||
case *ast.BasicLit:
|
||||
f.decls[vSpec.Names[i].Name] = v.Value
|
||||
|
||||
if e := f.addNode(v); e != nil {
|
||||
return e
|
||||
}
|
||||
// f.decls[vSpec.Names[i].Name] = v.Value
|
||||
default:
|
||||
// log.Printf("Name: %s - Unsupported ValueSpec: %+v\n", vSpec.Names[i].Name, v)
|
||||
}
|
||||
|
@ -94,6 +98,29 @@ func (f *file) findDecals() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (f *file) addNode(node ast.Node) error {
|
||||
switch x := node.(type) {
|
||||
case *ast.BasicLit:
|
||||
return f.add(x.Value)
|
||||
case *ast.Ident:
|
||||
return f.add(x.Name)
|
||||
default:
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *file) add(s string) error {
|
||||
s, err := strconv.Unquote(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, ok := f.decls[s]; !ok {
|
||||
// fmt.Println(">>>TODO parser/visitor.go:98: s ", s)
|
||||
f.decls[s] = s
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *file) findOpenCalls() error {
|
||||
var err error
|
||||
f.walk(func(node ast.Node) bool {
|
||||
|
@ -107,30 +134,10 @@ func (f *file) findOpenCalls() error {
|
|||
return true
|
||||
}
|
||||
|
||||
switch x := ce.Args[0].(type) {
|
||||
|
||||
case *ast.BasicLit:
|
||||
s, err := strconv.Unquote(x.Value)
|
||||
if err != nil {
|
||||
err = nil
|
||||
return false
|
||||
}
|
||||
f.decls[s] = s
|
||||
case *ast.Ident:
|
||||
val, ok := f.decls[x.Name]
|
||||
if !ok {
|
||||
//TODO: Add ERRORs list to file type and return after iteration!
|
||||
// log.Printf("Could not find identifier[%s] in decls map\n", x.Name)
|
||||
return true
|
||||
}
|
||||
s, err := strconv.Unquote(val)
|
||||
if err != nil {
|
||||
err = nil
|
||||
return false
|
||||
}
|
||||
f.decls[s] = s
|
||||
|
||||
default:
|
||||
// fmt.Println(">>>TODO parser/visitor.go:138: findOpenCalls ", ce.Args[0])
|
||||
if e := f.addNode(ce.Args[0]); e != nil {
|
||||
err = e
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
|
@ -151,29 +158,10 @@ func (f *file) findWalkCalls() error {
|
|||
return true
|
||||
}
|
||||
|
||||
switch x := ce.Args[0].(type) {
|
||||
|
||||
case *ast.BasicLit:
|
||||
s, err := strconv.Unquote(x.Value)
|
||||
if err != nil {
|
||||
err = nil
|
||||
return false
|
||||
}
|
||||
f.decls[s] = s
|
||||
case *ast.Ident:
|
||||
val, ok := f.decls[x.Name]
|
||||
if !ok {
|
||||
//TODO: Add ERRORs list to file type and return after iteration!
|
||||
// log.Printf("Could not find identifier[%s] in decls map\n", x.Name)
|
||||
return true
|
||||
}
|
||||
s, err := strconv.Unquote(val)
|
||||
if err != nil {
|
||||
err = nil
|
||||
return false
|
||||
}
|
||||
f.decls[s] = s
|
||||
default:
|
||||
// fmt.Println(">>>TODO parser/visitor.go:138: findWalkCalls ", ce.Args[0])
|
||||
if e := f.addNode(ce.Args[0]); e != nil {
|
||||
err = e
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
|
|
|
@ -96,7 +96,7 @@ func Test_Walk(t *testing.T) {
|
|||
r := require.New(t)
|
||||
|
||||
files := map[string]os.FileInfo{}
|
||||
err := Walk("/internal/testdata/app", func(path string, info os.FileInfo, err error) error {
|
||||
err := Walk("/pkging/pkgtest/internal/testdata/app", func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@ import (
|
|||
"compress/gzip"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/markbates/pkger/pkging"
|
||||
)
|
||||
|
||||
func (pkg *Pkger) MarshalEmbed() ([]byte, error) {
|
||||
|
@ -23,7 +21,7 @@ func (pkg *Pkger) MarshalEmbed() ([]byte, error) {
|
|||
return []byte(s), nil
|
||||
}
|
||||
|
||||
func UnmarshalEmbed(in []byte) (pkging.Pkger, error) {
|
||||
func UnmarshalEmbed(in []byte) (*Pkger, error) {
|
||||
b := make([]byte, len(in))
|
||||
if _, err := hex.Decode(b, in); err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -3,12 +3,12 @@ package mem_test
|
|||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/markbates/pkger/here"
|
||||
"github.com/markbates/pkger/parser"
|
||||
"github.com/markbates/pkger/pkging/mem"
|
||||
"github.com/markbates/pkger/pkging/pkgtest"
|
||||
"github.com/markbates/pkger/pkging/stdos"
|
||||
"github.com/markbates/pkger/pkging/stuffing"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -16,24 +16,9 @@ import (
|
|||
func Test_Pkger_Embedding(t *testing.T) {
|
||||
r := require.New(t)
|
||||
|
||||
pwd, err := os.Getwd()
|
||||
info, err := pkgtest.App()
|
||||
r.NoError(err)
|
||||
|
||||
ch := filepath.Join(pwd,
|
||||
"..",
|
||||
"..",
|
||||
"internal",
|
||||
"testdata",
|
||||
"app")
|
||||
|
||||
info := here.Info{
|
||||
Dir: ch,
|
||||
ImportPath: "github.com/markbates/pkger/internal/testdata/app",
|
||||
}
|
||||
here.Cache(info.ImportPath, func(s string) (here.Info, error) {
|
||||
return info, nil
|
||||
})
|
||||
|
||||
paths, err := parser.Parse(info)
|
||||
r.NoError(err)
|
||||
|
||||
|
@ -42,7 +27,55 @@ func Test_Pkger_Embedding(t *testing.T) {
|
|||
ps[i] = p.String()
|
||||
}
|
||||
|
||||
r.Equal(inbed, ps)
|
||||
r.Equal(pkgtest.AppPaths, ps)
|
||||
|
||||
base, err := mem.New(info)
|
||||
r.NoError(err)
|
||||
|
||||
disk, err := stdos.New(info)
|
||||
r.NoError(err)
|
||||
|
||||
err = disk.Walk("/", func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
f, err := disk.Open(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return base.Add(f)
|
||||
|
||||
})
|
||||
r.NoError(err)
|
||||
|
||||
var res []string
|
||||
err = base.Walk("/", func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
res = append(res, path)
|
||||
return nil
|
||||
})
|
||||
|
||||
r.NoError(err)
|
||||
r.Equal(rootWalk, res)
|
||||
|
||||
res = []string{}
|
||||
err = base.Walk("/public", func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
res = append(res, path)
|
||||
return nil
|
||||
})
|
||||
|
||||
r.NoError(err)
|
||||
r.Equal(pubWalk[1:], res)
|
||||
|
||||
bb := &bytes.Buffer{}
|
||||
|
||||
|
@ -52,7 +85,7 @@ func Test_Pkger_Embedding(t *testing.T) {
|
|||
pkg, err := mem.UnmarshalEmbed(bb.Bytes())
|
||||
r.NoError(err)
|
||||
|
||||
var res []string
|
||||
res = []string{}
|
||||
err = pkg.Walk("/", func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -62,51 +95,45 @@ func Test_Pkger_Embedding(t *testing.T) {
|
|||
})
|
||||
|
||||
r.NoError(err)
|
||||
r.Equal(inbed, res)
|
||||
r.Equal(rootWalk, res)
|
||||
|
||||
res = []string{}
|
||||
err = pkg.Walk("/public", func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
res = append(res, path)
|
||||
return nil
|
||||
})
|
||||
|
||||
r.NoError(err)
|
||||
r.Equal(pubWalk, res)
|
||||
}
|
||||
|
||||
var inbed = []string{
|
||||
"github.com/gobuffalo/buffalo:/",
|
||||
"github.com/gobuffalo/buffalo:/render",
|
||||
"github.com/gobuffalo/buffalo:/render/auto.go",
|
||||
"github.com/gobuffalo/buffalo:/render/auto_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/download.go",
|
||||
"github.com/gobuffalo/buffalo:/render/download_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/func.go",
|
||||
"github.com/gobuffalo/buffalo:/render/func_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/helpers.go",
|
||||
"github.com/gobuffalo/buffalo:/render/html.go",
|
||||
"github.com/gobuffalo/buffalo:/render/html_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/js.go",
|
||||
"github.com/gobuffalo/buffalo:/render/js_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/json.go",
|
||||
"github.com/gobuffalo/buffalo:/render/json_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/markdown_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/options.go",
|
||||
"github.com/gobuffalo/buffalo:/render/partials_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/plain.go",
|
||||
"github.com/gobuffalo/buffalo:/render/plain_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/render.go",
|
||||
"github.com/gobuffalo/buffalo:/render/render_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/renderer.go",
|
||||
"github.com/gobuffalo/buffalo:/render/sse.go",
|
||||
"github.com/gobuffalo/buffalo:/render/string.go",
|
||||
"github.com/gobuffalo/buffalo:/render/string_map.go",
|
||||
"github.com/gobuffalo/buffalo:/render/string_map_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/string_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/template.go",
|
||||
"github.com/gobuffalo/buffalo:/render/template_engine.go",
|
||||
"github.com/gobuffalo/buffalo:/render/template_helpers.go",
|
||||
"github.com/gobuffalo/buffalo:/render/template_helpers_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/template_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/xml.go",
|
||||
"github.com/gobuffalo/buffalo:/render/xml_test.go",
|
||||
"github.com/markbates/pkger/internal/testdata/app:/",
|
||||
"github.com/markbates/pkger/internal/testdata/app:/public",
|
||||
"github.com/markbates/pkger/internal/testdata/app:/public/images",
|
||||
"github.com/markbates/pkger/internal/testdata/app:/public/images/mark-small.png",
|
||||
"github.com/markbates/pkger/internal/testdata/app:/public/images/mark.png",
|
||||
"github.com/markbates/pkger/internal/testdata/app:/public/images/mark_250px.png",
|
||||
"github.com/markbates/pkger/internal/testdata/app:/public/images/mark_400px.png",
|
||||
"github.com/markbates/pkger/internal/testdata/app:/public/index.html",
|
||||
var pubWalk = []string{
|
||||
"app:/",
|
||||
"app:/public",
|
||||
"app:/public/images",
|
||||
"app:/public/images/mark-small.png",
|
||||
"app:/public/images/mark.png",
|
||||
"app:/public/images/mark_250px.png",
|
||||
"app:/public/images/mark_400px.png",
|
||||
"app:/public/index.html",
|
||||
}
|
||||
|
||||
var rootWalk = []string{
|
||||
"app:/",
|
||||
"app:/go.mod",
|
||||
"app:/main.go",
|
||||
"app:/public",
|
||||
"app:/public/images",
|
||||
"app:/public/images/mark-small.png",
|
||||
"app:/public/images/mark.png",
|
||||
"app:/public/images/mark_250px.png",
|
||||
"app:/public/images/mark_400px.png",
|
||||
"app:/public/index.html",
|
||||
"app:/templates",
|
||||
"app:/templates/a.txt",
|
||||
"app:/templates/b",
|
||||
"app:/templates/b/b.txt",
|
||||
}
|
||||
|
|
|
@ -3,14 +3,13 @@ package mem
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/markbates/pkger/here"
|
||||
"github.com/markbates/pkger/pkging"
|
||||
"github.com/markbates/pkger/pkging/pkgtest"
|
||||
)
|
||||
|
||||
func Test_Pkger(t *testing.T) {
|
||||
suite, err := pkgtest.NewSuite("memos", func() (pkging.Pkger, error) {
|
||||
info, err := here.Current()
|
||||
info, err := pkgtest.App()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
package pkgtest
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/markbates/pkger/here"
|
||||
)
|
||||
|
||||
// App returns here.info that represents the
|
||||
// ./internal/testdata/app. This should be used
|
||||
// by tests.
|
||||
func App() (here.Info, error) {
|
||||
her, err := here.Package("github.com/markbates/pkger")
|
||||
if err != nil {
|
||||
return her, err
|
||||
}
|
||||
var info here.Info
|
||||
|
||||
ch := filepath.Join(
|
||||
her.Dir,
|
||||
"pkging",
|
||||
"pkgtest",
|
||||
"internal",
|
||||
"testdata",
|
||||
"app")
|
||||
|
||||
info.Dir = ch
|
||||
info.ImportPath = "app"
|
||||
return here.Cache(info.ImportPath, func(s string) (here.Info, error) {
|
||||
return info, nil
|
||||
})
|
||||
}
|
||||
|
||||
var AppPaths = []string{
|
||||
"app:/",
|
||||
"app:/public",
|
||||
"app:/public/images",
|
||||
"app:/public/images/mark-small.png",
|
||||
"app:/public/images/mark.png",
|
||||
"app:/public/images/mark_250px.png",
|
||||
"app:/public/images/mark_400px.png",
|
||||
"app:/public/index.html",
|
||||
"github.com/gobuffalo/buffalo:/",
|
||||
"github.com/gobuffalo/buffalo:/render",
|
||||
"github.com/gobuffalo/buffalo:/render/auto.go",
|
||||
"github.com/gobuffalo/buffalo:/render/auto_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/download.go",
|
||||
"github.com/gobuffalo/buffalo:/render/download_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/func.go",
|
||||
"github.com/gobuffalo/buffalo:/render/func_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/helpers.go",
|
||||
"github.com/gobuffalo/buffalo:/render/html.go",
|
||||
"github.com/gobuffalo/buffalo:/render/html_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/js.go",
|
||||
"github.com/gobuffalo/buffalo:/render/js_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/json.go",
|
||||
"github.com/gobuffalo/buffalo:/render/json_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/markdown_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/options.go",
|
||||
"github.com/gobuffalo/buffalo:/render/partials_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/plain.go",
|
||||
"github.com/gobuffalo/buffalo:/render/plain_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/render.go",
|
||||
"github.com/gobuffalo/buffalo:/render/render_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/renderer.go",
|
||||
"github.com/gobuffalo/buffalo:/render/sse.go",
|
||||
"github.com/gobuffalo/buffalo:/render/string.go",
|
||||
"github.com/gobuffalo/buffalo:/render/string_map.go",
|
||||
"github.com/gobuffalo/buffalo:/render/string_map_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/string_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/template.go",
|
||||
"github.com/gobuffalo/buffalo:/render/template_engine.go",
|
||||
"github.com/gobuffalo/buffalo:/render/template_helpers.go",
|
||||
"github.com/gobuffalo/buffalo:/render/template_helpers_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/template_test.go",
|
||||
"github.com/gobuffalo/buffalo:/render/xml.go",
|
||||
"github.com/gobuffalo/buffalo:/render/xml_test.go",
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
module app
|
||||
|
||||
go 1.13
|
||||
|
||||
require github.com/markbates/pkger v0.0.0
|
||||
|
||||
replace github.com/markbates/pkger => ../../../../../
|
|
@ -43,7 +43,7 @@ func main() {
|
|||
// : - seperator between the module/package name, pkg, and the "file path"
|
||||
// path - this is the ABSOLUTE path to the file/directory you want, as relative
|
||||
// to the root of the module/package's go.mod file.
|
||||
dir, err := pkger.Open("github.com/markbates/pkger/internal/testdata/app:/public")
|
||||
dir, err := pkger.Open("app:/public")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
Before Width: | Height: | Size: 634 KiB After Width: | Height: | Size: 634 KiB |
Before Width: | Height: | Size: 48 MiB After Width: | Height: | Size: 48 MiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
|
@ -57,36 +57,6 @@ func (s Suite) Test(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// func (s Suite) clone() (Suite, error) {
|
||||
// if ns, ok := s.Pkger.(Newable); ok {
|
||||
// pkg, err := ns.New()
|
||||
// if err != nil {
|
||||
// return s, err
|
||||
// }
|
||||
// s, err = NewSuite(pkg)
|
||||
// if err != nil {
|
||||
// return s, err
|
||||
// }
|
||||
// }
|
||||
// if ns, ok := s.Pkger.(WithRootable); ok {
|
||||
// dir, err := ioutil.TempDir("")
|
||||
// if err != nil {
|
||||
// return s, err
|
||||
// }
|
||||
// // defer opkg.RemoveAll(dir)
|
||||
//
|
||||
// pkg, err := ns.WithRoot(dir)
|
||||
// if err != nil {
|
||||
// return s, err
|
||||
// }
|
||||
// s, err = NewSuite(pkg)
|
||||
// if err != nil {
|
||||
// return s, err
|
||||
// }
|
||||
// }
|
||||
// return s, nil
|
||||
// }
|
||||
|
||||
func (s Suite) Run(t *testing.T, name string, fn func(t *testing.T)) {
|
||||
t.Run(name, func(st *testing.T) {
|
||||
fn(st)
|
||||
|
@ -95,10 +65,6 @@ func (s Suite) Run(t *testing.T, name string, fn func(t *testing.T)) {
|
|||
|
||||
func (s Suite) sub(t *testing.T, m reflect.Method) {
|
||||
name := fmt.Sprintf("%s/%s", s.Name, m.Name)
|
||||
// s, err := s.clone()
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
s.Run(t, name, func(st *testing.T) {
|
||||
m.Func.Call([]reflect.Value{
|
||||
reflect.ValueOf(s),
|
||||
|
@ -476,6 +442,7 @@ func (s Suite) Test_Walk(t *testing.T) {
|
|||
|
||||
pkg, err := s.Make()
|
||||
r.NoError(err)
|
||||
|
||||
r.NoError(s.LoadFolder(pkg))
|
||||
|
||||
cur, err := pkg.Current()
|
||||
|
@ -506,16 +473,16 @@ func (s Suite) Test_Walk(t *testing.T) {
|
|||
r.NoError(err)
|
||||
|
||||
exp := []string{
|
||||
"github.com/markbates/pkger:/",
|
||||
"github.com/markbates/pkger:/main.go",
|
||||
"github.com/markbates/pkger:/public",
|
||||
"github.com/markbates/pkger:/public/images",
|
||||
"github.com/markbates/pkger:/public/images/mark.png",
|
||||
"github.com/markbates/pkger:/public/index.html",
|
||||
"github.com/markbates/pkger:/templates",
|
||||
"github.com/markbates/pkger:/templates/a.txt",
|
||||
"github.com/markbates/pkger:/templates/b",
|
||||
"github.com/markbates/pkger:/templates/b/b.txt",
|
||||
"app:/",
|
||||
"app:/main.go",
|
||||
"app:/public",
|
||||
"app:/public/images",
|
||||
"app:/public/images/mark.png",
|
||||
"app:/public/index.html",
|
||||
"app:/templates",
|
||||
"app:/templates/a.txt",
|
||||
"app:/templates/b",
|
||||
"app:/templates/b/b.txt",
|
||||
}
|
||||
r.Equal(exp, act)
|
||||
})
|
||||
|
|
|
@ -4,25 +4,25 @@ import (
|
|||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"github.com/markbates/pkger/here"
|
||||
"github.com/markbates/pkger/pkging"
|
||||
"github.com/markbates/pkger/pkging/pkgtest"
|
||||
)
|
||||
|
||||
func Test_Pkger(t *testing.T) {
|
||||
suite, err := pkgtest.NewSuite("stdos", func() (pkging.Pkger, error) {
|
||||
her, err := here.Current()
|
||||
info, err := pkgtest.App()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dir, err := ioutil.TempDir("", "stdos")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
her.Dir = dir
|
||||
info.Dir = dir
|
||||
|
||||
mypkging, err := New(her)
|
||||
mypkging, err := New(info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|