Skip to content

Commit 318768d

Browse files
committed
remove pkger dependency - update for embed
1 parent bde8743 commit 318768d

File tree

13 files changed

+237
-341
lines changed

13 files changed

+237
-341
lines changed

.github/workflows/jiffy-build.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,5 @@ jobs:
3131
- name: Tidy
3232
run: go mod tidy
3333

34-
- name: Install pkger
35-
run: go install github.com/markbates/pkger
36-
37-
- name: Run pkger
38-
run: ./pkgtemplates.sh
39-
4034
- name: Build
4135
run: go build -v .

.github/workflows/rel.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ jobs:
3434
- name: Tidy
3535
run: go mod tidy
3636

37-
- name: Install pkger
38-
run: go install github.com/markbates/pkger
39-
40-
- name: Run pkger
41-
run: ./pkgtemplates.sh
42-
4337
- name: Build darwin-amd64
4438
run: GOOS=darwin GOARCH=amd64 go build -v -o jiffy
4539

.vscode/launch.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": []
7+
}

Makefile

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
default:
2-
./pkgtemplates.sh
32
GOOS=darwin go build -v -o jiffy
43

54
install-mac:
6-
./pkgtemplates.sh
75
GOOS=darwin go build -v -o jiffy
86
mv jiffy /usr/local/bin
97

108
install-linux:
11-
./pkgtemplates.sh
129
GOOS=linux go build -v -o jiffy
1310
mv jiffy /usr/local/bin
1411

1512
docker:
16-
./pkgtemplates.sh
1713
GOOS=linux go build -v -o jiffy
18-
# docker build -t pkger:jiffy .
19-
# docker run -p 3000:3000 pkger:jiffy
14+
# docker build -t jiffy .
15+
# docker run -p 3000:3000 jiffy
2016

2117
all:
22-
./pkgtemplates.sh
2318

2419
# macos
2520
GOOS=darwin GOARCH=amd64 go build -v -o jiffy

docs/credits/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,6 @@ <h2 id="packages-and-libraries">Packages and libraries</h2>
19141914
<li><a href="https://github.com/SAP/go-hdb">go-hdb</a></li>
19151915
<li><a href="https://github.com/garyburd/redigo">redigo</a></li>
19161916
<li><a href="https://github.com/bradfitz/gomemcache">memcache</a></li>
1917-
<li><a href="https://github.com/markbates/pkger">pkger</a></li>
19181917
</ul>
19191918
<h2 id="tooling">Tooling</h2>
19201919
<ul>

docs/index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@
578578
"title": "Credits",
579579
"tags": [],
580580
"description": "",
581-
"content": "Packages and libraries sqlx jwt-go go-sql-driver/mysql lib/pq go-sqlite3 go-mssqldb go-hdb redigo memcache pkger Tooling Hugo Hugo Learn Theme "
581+
"content": "Packages and libraries sqlx jwt-go go-sql-driver/mysql lib/pq go-sqlite3 go-mssqldb go-hdb redigo memcache Tooling Hugo Hugo Learn Theme "
582582
},
583583
{
584584
"uri": "https://1414c.github.io/jiffy/showcase/",

docs/index.xml

Lines changed: 143 additions & 142 deletions
Large diffs are not rendered by default.

gen/generator.go

Lines changed: 16 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"time"
1313

1414
"github.com/1414C/sqac/common"
15-
"github.com/markbates/pkger"
1615
)
1716

1817
// Info is used to hold name-value-pairs for Entity definitions
@@ -115,8 +114,6 @@ const (
115114

116115
// CreateModelFile generates a model file for the Entity using the user-defined model.json file in conjunction
117116
// with the model.gotmpl text/template. Returns the fully-qualified file-name / error.
118-
// pkger is used to bundle the .gotmpl files into the binary. Pkger implements the File interface, so the
119-
// file handling is a little more pedantic than it would be with ioutil.
120117
func (ent *Entity) CreateModelFile(tDir string, ef embed.FS) (fName string, err error) {
121118

122119
// new part
@@ -373,48 +370,34 @@ func (ent *Entity) CreateModelExtensionPointsFile(tDir string, ef embed.FS) (fNa
373370
// =============================================================================================
374371
// static generation functions
375372
// =============================================================================================
376-
// GenerateStaticTemplates reads the ./static folder and uses Glob
377-
// to execute each template in-turn. Returns the fully-qualified
378-
// file-names or an error. Processes .gotmpl files into .go files.
379-
func (s *Static) GenerateStaticTemplates() (fNames []string, err error) {
373+
// GenerateStaticTemplates reads the ./static folder and executes each template in-turn.
374+
// Returns the fully-qualified file-names or an error. Processes .gotmpl files into .go files.
375+
func (s *Static) GenerateStaticTemplates(ef embed.FS) (fNames []string, err error) {
380376

381-
// begin of new part
382-
tmlFiles, err := glob(s.SrcDir, "*"+".gotmpl")
377+
// rewrite to use embed
378+
dirEntries, err := ef.ReadDir(s.SrcDir)
383379
if err != nil {
380+
log.Printf("failed to read %s: got: %s", s.SrcDir, err.Error())
384381
return nil, err
385382
}
386-
// end of new part
387-
388-
for _, f := range tmlFiles {
389383

390-
// start of new part
391-
fi, err := pkger.Stat(f)
392-
if err != nil {
393-
log.Printf("Stat: %v\n", err)
394-
return nil, err
395-
}
384+
for _, dirEntry := range dirEntries {
396385

397-
tf, err := pkger.Open(f)
398-
if err != nil {
399-
log.Printf("Open: %v\n", err)
400-
return nil, err
386+
if dirEntry.IsDir() {
387+
continue
401388
}
402-
defer tf.Close()
403389

404-
// read the template source from pkger
405-
buf := make([]byte, fi.Size())
406-
_, err = tf.Read(buf)
390+
tf, err := ef.ReadFile(s.SrcDir + "/" + dirEntry.Name())
407391
if err != nil {
408-
log.Printf("Unable to read template: %s %v\n", f, err)
392+
log.Printf("failed to read %s: got: %s", s.SrcDir+"/"+dirEntry.Name(), err.Error())
409393
return nil, err
410394
}
411395

412-
st := template.Must(template.New("Static template").Parse(string(buf)))
396+
st := template.Must(template.New("Static template").Parse(string(tf)))
413397
if st == nil {
414398
log.Printf("Parse error: %v\n", err)
415399
return nil, err
416400
}
417-
// end of new part
418401

419402
// create the file-path if required
420403
_, err = os.Stat(s.DstDir)
@@ -423,7 +406,8 @@ func (s *Static) GenerateStaticTemplates() (fNames []string, err error) {
423406
}
424407

425408
// create the static source file
426-
fileName := filepath.Base(f)
409+
// fileName := filepath.Base(f)
410+
fileName := filepath.Base(dirEntry.Name())
427411
fileName = strings.TrimSuffix(fileName, "tmpl")
428412
f, err := os.Create(s.DstDir + "/" + fileName)
429413
if err != nil {
@@ -459,14 +443,6 @@ func (s *Static) GenerateGoMod(ef embed.FS) error {
459443
if err != nil {
460444
return err
461445
}
462-
// end of new part
463-
464-
// check the controller file path and create if required
465-
// tDir = tDir + "/controllers"
466-
// _, err = os.Stat(tDir)
467-
// if err != nil {
468-
// os.Mkdir(tDir, 0755)
469-
// }
470446

471447
// create the go.mod file
472448
// tfDir := tDir + "go.mod"
@@ -1365,37 +1341,16 @@ func superCleanString(s string) string {
13651341
return s
13661342
}
13671343

1368-
// prepareTemplate is used to read a template source from the pkger
1369-
// or local location, create a *Template and return it to the caller.
1344+
// prepareTemplate is used to read a template source from the embedded
1345+
// location, create a *Template and return it to the caller.
13701346
func prepareTemplate(templateName string, ef embed.FS) (*template.Template, error) {
1371-
// stat for .gotmpl file size
1372-
//fi, err := pkger.Stat(templateName)
1373-
//if err != nil {
1374-
// log.Printf("Stat: %v\n", err)
1375-
// return nil, err
1376-
//}
13771347

13781348
tf, err := ef.ReadFile(templateName)
13791349
if err != nil {
13801350
log.Printf("ReadFile: %v\n", err)
13811351
return nil, err
13821352
}
13831353

1384-
// tf, err := ef.Open(templateName)
1385-
// if err != nil {
1386-
// log.Printf("Open: %v\n", err)
1387-
// return nil, err
1388-
// }
1389-
// defer tf.Close()
1390-
1391-
// read the template source from pkger
1392-
// buf := make([]byte, fi.Size())
1393-
// _, err = tf.Read(buf)
1394-
// if err != nil {
1395-
// log.Printf("Unable to read template %s\n", templateName)
1396-
// return nil, err
1397-
// }
1398-
13991354
// create the template
14001355
// t := template.Must(template.New("Entity model template").Parse(string(buf)))
14011356
t := template.Must(template.New("Entity model template").Parse(string(tf)))
@@ -1406,40 +1361,6 @@ func prepareTemplate(templateName string, ef embed.FS) (*template.Template, erro
14061361
return t, nil
14071362
}
14081363

1409-
// glob is used to read files matching the pattern string
1410-
// parameter from the directory specified by the dir parameter.
1411-
// There is a slight argument for making this walk the tree, but
1412-
// the needs of jiffy are mostly served by reading single directories.
1413-
// The pkger.Walk(...) function would be a place to start.
1414-
func glob(dir, pattern string) ([]string, error) {
1415-
m := make([]string, 0)
1416-
fi, err := pkger.Stat(dir)
1417-
if err != nil {
1418-
return nil, err
1419-
}
1420-
if !fi.IsDir() {
1421-
return nil, err
1422-
}
1423-
d, err := pkger.Open(dir)
1424-
if err != nil {
1425-
return nil, err
1426-
}
1427-
defer d.Close()
1428-
1429-
names, _ := d.Readdir(-1)
1430-
1431-
for _, n := range names {
1432-
matched, err := filepath.Match(pattern, n.Name())
1433-
if err != nil {
1434-
return m, err
1435-
}
1436-
if matched {
1437-
m = append(m, dir+"/"+n.Name())
1438-
}
1439-
}
1440-
return m, nil
1441-
}
1442-
14431364
// ExecuteGoTools runs gofmt -w and goimports on the specified file
14441365
func ExecuteGoTools(fileName string) error {
14451366

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ require (
88
github.com/denisenkom/go-mssqldb v0.12.3
99
github.com/go-sql-driver/mysql v1.8.1
1010
github.com/lib/pq v1.10.9
11-
github.com/markbates/pkger v0.17.1 // v0.16.0
1211
github.com/mattn/go-sqlite3 v2.0.1+incompatible //v2.0.1+incompatible
1312
// github.com/golang-jwt/jwt/v5 v5.2.1
1413
)
1514

1615
require (
17-
github.com/gobuffalo/here v0.6.0 // indirect
1816
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
1917
golang.org/x/crypto v0.21.0 // indirect; v0.0.0-20211215165025-cf75a172585e // indirect
2018
golang.org/x/text v0.14.0 // indirect

go.sum

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,25 @@ github.com/Azure/azure-sdk-for-go/sdk/internal v0.7.0/go.mod h1:yqy467j36fJxcRV2
88
github.com/SAP/go-hdb v1.8.11 h1:CfzNLy9ymcwMbAMWYpkd8NezbVKYQcNxpRqOPfBNHAE=
99
github.com/SAP/go-hdb v1.8.11/go.mod h1:AjSrmLmZEZcX17tS41J9/bFYvAKqLFuZ28v5h79Yn1c=
1010
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
11-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1211
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1312
github.com/denisenkom/go-mssqldb v0.12.3 h1:pBSGx9Tq67pBOTLmxNuirNTeB8Vjmf886Kx+8Y+8shw=
1413
github.com/denisenkom/go-mssqldb v0.12.3/go.mod h1:k0mtMFOnU+AihqFxPMiF05rtiDrorD1Vrm1KEz5hxDo=
1514
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
1615
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
1716
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
18-
github.com/gobuffalo/here v0.6.0 h1:hYrd0a6gDmWxBM4TnrGw8mQg24iSVoIkHEk7FodQcBI=
19-
github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM=
2017
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
2118
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
2219
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
2320
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
2421
github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI=
25-
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
26-
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
27-
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
2822
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
2923
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
30-
github.com/markbates/pkger v0.17.1 h1:/MKEtWqtc0mZvu9OinB9UzVN9iYCwLWuyUv4Bw+PCno=
31-
github.com/markbates/pkger v0.17.1/go.mod h1:0JoVlrol20BSywW79rN3kdFFsE5xYM+rSCQDXbLhiuI=
3224
github.com/mattn/go-sqlite3 v2.0.1+incompatible h1:xQ15muvnzGBHpIpdrNi1DA5x0+TcBZzsIDwmw9uTHzw=
3325
github.com/mattn/go-sqlite3 v2.0.1+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
3426
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
3527
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
36-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3728
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3829
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
39-
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
40-
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
4130
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
4231
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
4332
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
@@ -59,11 +48,7 @@ golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
5948
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
6049
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
6150
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
62-
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
63-
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
64-
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
6551
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
6652
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
6753
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
68-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
6954
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)