2019-09-22 00:38:03 +03:00
|
|
|
package pkgutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2019-09-22 00:52:07 +03:00
|
|
|
"fmt"
|
2019-09-22 00:38:03 +03:00
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/markbates/pkger/here"
|
|
|
|
"github.com/markbates/pkger/pkging"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Dump(w io.Writer, pkg pkging.Pkger) error {
|
|
|
|
d := struct {
|
2019-09-22 00:52:07 +03:00
|
|
|
Type string
|
2019-09-22 00:38:03 +03:00
|
|
|
Info here.Info
|
|
|
|
Paths map[string]os.FileInfo
|
|
|
|
}{
|
2019-09-22 00:52:07 +03:00
|
|
|
Type: fmt.Sprintf("%T", pkg),
|
2019-09-22 00:38:03 +03:00
|
|
|
Paths: map[string]os.FileInfo{},
|
|
|
|
}
|
|
|
|
|
|
|
|
info, err := pkg.Current()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
d.Info = info
|
|
|
|
|
|
|
|
err = pkg.Walk("/", func(path string, info os.FileInfo, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
d.Paths[path] = info
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
enc := json.NewEncoder(w)
|
|
|
|
enc.SetIndent("", " ")
|
|
|
|
|
|
|
|
if err := enc.Encode(d); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|