~repos /gromer

#golang#htmx#ssr

git clone https://pyrossh.dev/repos/gromer.git

gromer is a framework and cli to build multipage web apps in golang using htmx and alpinejs.


6c654882 Peter John

tag: v0.12.0

v0.12.0

3 years ago
update golang to v1.18
Files changed (3) hide show
  1. collection.go +23 -24
  2. example/readme.md +1 -1
  3. go.mod +40 -7
collection.go CHANGED
@@ -11,51 +11,50 @@ import (
11
11
  _ "gocloud.dev/docstore/gcpfirestore"
12
12
  )
13
13
 
14
- type Collection struct {
14
+ type Collection[S any] struct {
15
15
  *docstore.Collection
16
16
  Type reflect.Type
17
17
  }
18
18
 
19
- func (c Collection) Query() *Query {
19
+ func (c *Collection[S]) Query() *Query[S] {
20
- return &Query{c.Collection.Query(), c, c.Type}
20
+ return &Query[S]{c.Collection.Query(), c}
21
21
  }
22
22
 
23
- type Query struct {
23
+ type Query[S any] struct {
24
24
  *docstore.Query
25
- Parent Collection
25
+ Parent *Collection[S]
26
- Type reflect.Type
27
26
  }
28
27
 
29
- func (q *Query) Where(fp docstore.FieldPath, op string, value interface{}) *Query {
28
+ func (q *Query[S]) Where(fp docstore.FieldPath, op string, value interface{}) *Query[S] {
30
- return &Query{q.Query.Where(fp, op, value), q.Parent, q.Type}
29
+ return &Query[S]{q.Query.Where(fp, op, value), q.Parent}
31
30
  }
32
31
 
33
- func (q *Query) Limit(n int) *Query {
32
+ func (q *Query[S]) Limit(n int) *Query[S] {
34
- return &Query{q.Query.Limit(n), q.Parent, q.Type}
33
+ return &Query[S]{q.Query.Limit(n), q.Parent}
35
34
  }
36
35
 
37
- func (q *Query) OrderBy(field, direction string) *Query {
36
+ func (q *Query[S]) OrderBy(field, direction string) *Query[S] {
38
- return &Query{q.Query.OrderBy(field, direction), q.Parent, q.Type}
37
+ return &Query[S]{q.Query.OrderBy(field, direction), q.Parent}
39
38
  }
40
39
 
41
- func (q *Query) One(ctx context.Context) (interface{}, int, error) {
40
+ func (q *Query[S]) One(ctx context.Context) (S, int, error) {
42
41
  results, err := q.All(ctx)
43
42
  if err != nil {
44
- return nil, 500, err
43
+ return *new(S), 500, err
45
44
  }
46
45
  arr := reflect.ValueOf(results)
47
46
  if arr.Len() == 0 {
48
- return nil, 404, fmt.Errorf("%s not found", q.Type.Name())
47
+ return *new(S), 404, fmt.Errorf("%s not found", q.Parent.Type.Name())
49
48
  }
50
- return arr.Index(0).Interface(), 200, nil
49
+ return arr.Index(0).Interface().(S), 200, nil
51
50
  }
52
51
 
53
- func (q *Query) All(ctx context.Context) (interface{}, error) {
52
+ func (q *Query[S]) All(ctx context.Context) ([]S, error) {
54
53
  iter := q.Get(ctx)
55
54
  defer iter.Stop()
56
- results := reflect.New(reflect.SliceOf(reflect.PtrTo(q.Type))).Elem()
55
+ results := reflect.New(reflect.SliceOf(reflect.PtrTo(q.Parent.Type))).Elem()
57
56
  for {
58
- v := reflect.New(q.Type)
57
+ v := reflect.New(q.Parent.Type)
59
58
  err := iter.Next(ctx, v.Interface())
60
59
  if err == io.EOF {
61
60
  break
@@ -65,13 +64,13 @@ func (q *Query) All(ctx context.Context) (interface{}, error) {
65
64
  results.Set(reflect.Append(results, v))
66
65
  }
67
66
  }
68
- return results.Interface(), nil
67
+ return results.Interface().([]S), nil
69
68
  }
70
69
 
71
- func GetCollection(project, env, name string, t interface{}) *Collection {
70
+ func NewCollection[S any](project, name string, t interface{}) *Collection[S] {
72
- coll, err := docstore.OpenCollection(context.Background(), fmt.Sprintf("firestore://projects/%s/databases/(default)/documents/%s?name_field=ID", project, env+"-"+name))
71
+ coll, err := docstore.OpenCollection(context.Background(), fmt.Sprintf("firestore://projects/%s/databases/(default)/documents/%s-%s?name_field=ID", project, project, name))
73
72
  if err != nil {
74
- log.Fatal().Stack().Err(err).Msgf("failed to GetCollection %s", name)
73
+ log.Fatal().Stack().Err(err).Msgf("failed to getTable %s", name)
75
74
  }
76
- return &Collection{coll, reflect.TypeOf(t)}
75
+ return &Collection[S]{coll, reflect.TypeOf(t)}
77
76
  }
example/readme.md CHANGED
@@ -6,7 +6,7 @@ It uses postgres as the database and sqlc to generate queries and models. It use
6
6
 
7
7
  # Requirements
8
8
 
9
- 1. go >= 1.16
9
+ 1. go >= 1.18
10
10
  2. docker >= 20
11
11
 
12
12
  # Running
go.mod CHANGED
@@ -1,9 +1,8 @@
1
1
  module github.com/pyros2097/gromer
2
2
 
3
- go 1.16
3
+ go 1.18
4
4
 
5
5
  require (
6
- github.com/aymerick/raymond v2.0.2+incompatible // indirect
7
6
  github.com/bradleyjkemp/cupaloy v2.3.0+incompatible
8
7
  github.com/franela/goblin v0.0.0-20211003143422-0a4f594942bf
9
8
  github.com/go-playground/validator/v10 v10.9.0
@@ -12,10 +11,35 @@ require (
12
11
  github.com/gorilla/mux v1.8.0
13
12
  github.com/imdario/mergo v0.3.12
14
13
  github.com/lib/pq v1.10.4
15
- github.com/markbates/inflect v1.0.4 // indirect
16
- github.com/microcosm-cc/bluemonday v1.0.16 // indirect
17
14
  github.com/rs/zerolog v1.26.1
18
15
  github.com/segmentio/go-camelcase v0.0.0-20160726192923-7085f1e3c734
16
+ github.com/stretchr/testify v1.7.0
17
+ gocloud.dev v0.24.0
18
+ golang.org/x/mod v0.5.1
19
+ )
20
+
21
+ require (
22
+ cloud.google.com/go v0.94.0 // indirect
23
+ cloud.google.com/go/firestore v1.5.0 // indirect
24
+ github.com/aymerick/douceur v0.2.0 // indirect
25
+ github.com/aymerick/raymond v2.0.2+incompatible // indirect
26
+ github.com/davecgh/go-spew v1.1.1 // indirect
27
+ github.com/go-playground/locales v0.14.0 // indirect
28
+ github.com/go-playground/universal-translator v0.18.0 // indirect
29
+ github.com/gobuffalo/envy v1.6.5 // indirect
30
+ github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
31
+ github.com/golang/protobuf v1.5.2 // indirect
32
+ github.com/google/go-cmp v0.5.6 // indirect
33
+ github.com/google/wire v0.5.0 // indirect
34
+ github.com/googleapis/gax-go/v2 v2.1.0 // indirect
35
+ github.com/gorilla/css v1.0.0 // indirect
36
+ github.com/joho/godotenv v1.3.0 // indirect
37
+ github.com/leodido/go-urn v1.2.1 // indirect
38
+ github.com/markbates/inflect v1.0.4 // indirect
39
+ github.com/microcosm-cc/bluemonday v1.0.16 // indirect
40
+ github.com/pkg/errors v0.9.1 // indirect
41
+ github.com/pmezard/go-difflib v1.0.0 // indirect
42
+ github.com/russross/blackfriday v1.5.2 // indirect
19
43
  github.com/sergi/go-diff v1.2.0 // indirect
20
44
  github.com/shurcooL/github_flavored_markdown v0.0.0-20210228213109-c3a9aa474629 // indirect
21
45
  github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636 // indirect
@@ -26,8 +50,17 @@ require (
26
50
  github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
27
51
  github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d // indirect
28
52
  github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e // indirect
29
- github.com/stretchr/testify v1.7.0
30
- gocloud.dev v0.24.0
31
- golang.org/x/mod v0.5.1
53
+ go.opencensus.io v0.23.0 // indirect
54
+ golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e // indirect
32
55
  golang.org/x/net v0.0.0-20211216030914-fe4d6282115f // indirect
56
+ golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
57
+ golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect
58
+ golang.org/x/text v0.3.7 // indirect
59
+ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
60
+ google.golang.org/api v0.56.0 // indirect
61
+ google.golang.org/appengine v1.6.7 // indirect
62
+ google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2 // indirect
63
+ google.golang.org/grpc v1.40.0 // indirect
64
+ google.golang.org/protobuf v1.27.1 // indirect
65
+ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
33
66
  )