pkger/pkging/pkgutil/stuff.go

62 lines
931 B
Go
Raw Normal View History

2019-10-21 17:27:04 +03:00
package pkgutil
import (
2019-12-04 01:40:04 +03:00
"fmt"
2019-10-21 17:27:04 +03:00
"io"
"os"
2019-12-04 01:36:58 +03:00
"strings"
2019-10-21 17:27:04 +03:00
"github.com/markbates/pkger/here"
2019-10-21 17:27:04 +03:00
"github.com/markbates/pkger/parser"
2019-10-25 17:19:27 +03:00
"github.com/markbates/pkger/pkging/embed"
2019-10-21 17:27:04 +03:00
"github.com/markbates/pkger/pkging/mem"
)
func Stuff(w io.Writer, c here.Info, decls parser.Decls) error {
pkg, err := mem.New(c)
if err != nil {
return err
}
files, err := decls.Files()
if err != nil {
return err
}
for _, pf := range files {
err = func() error {
2019-12-04 01:36:58 +03:00
if strings.HasSuffix(pf.Abs, ".tmp") {
return nil
}
2019-10-24 23:22:15 +03:00
df, err := os.Open(pf.Abs)
2019-10-21 17:27:04 +03:00
if err != nil {
2019-12-04 01:40:04 +03:00
return fmt.Errorf("could open stuff %s: %s", pf.Abs, err)
2019-10-21 17:27:04 +03:00
}
defer df.Close()
if err := pkg.Add(df); err != nil {
return err
}
return err
}()
if err != nil {
return err
}
}
2019-10-25 17:19:27 +03:00
b, err := pkg.MarshalJSON()
if err != nil {
return err
}
b, err = embed.Encode(b)
if err != nil {
return err
}
_, err = w.Write(b)
2019-10-21 17:27:04 +03:00
return nil
}