clown strike

This commit is contained in:
Mark Bates 2019-09-21 17:38:03 -04:00
parent b28e301e65
commit 158a7644ca
2 changed files with 51 additions and 1 deletions

View File

@ -1,16 +1,20 @@
package pkger
import (
"log"
"os"
"sync"
"github.com/markbates/pkger/pkging"
"github.com/markbates/pkger/pkging/pkgutil"
)
var current pkging.Pkger
var gil = &sync.RWMutex{}
func Apply(pkg pkging.Pkger, err error) error {
if err != nil {
if err := pkgutil.Dump(os.Stdout, pkg); err != nil {
log.Fatal(err)
return err
}
gil.Lock()

46
pkging/pkgutil/dump.go Normal file
View File

@ -0,0 +1,46 @@
package pkgutil
import (
"encoding/json"
"io"
"os"
"github.com/markbates/pkger/here"
"github.com/markbates/pkger/pkging"
)
func Dump(w io.Writer, pkg pkging.Pkger) error {
d := struct {
Info here.Info
Paths map[string]os.FileInfo
}{
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
}