Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support []Hoge #60 #61

Merged
merged 9 commits into from
May 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 44 additions & 38 deletions examples/different_dir/lock_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

120 changes: 64 additions & 56 deletions examples/different_dir/lock_label_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type Lock struct {
MapInterface map[string]interface{} `firestore:"map_interface"`
Nested Nested `firestore:"nested"`
NestedPtr *Nested `firestore:"nested_ptr"`
SliceString []string `firestore:"slice_string"`
SliceNested []*Nested `firestore:"slice_nested"`
Meta
}

Expand Down
28 changes: 12 additions & 16 deletions examples/task_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions examples/task_label_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 1 addition & 14 deletions generator/structGenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/go-generalize/volcago/pkg/fsutil"
"github.com/go-generalize/volcago/pkg/gocodegen"
"github.com/go-generalize/volcago/pkg/sliceutil"
"github.com/go-utils/cont"
"github.com/go-utils/gopackages"
"github.com/iancoleman/strcase"
"golang.org/x/xerrors"
Expand Down Expand Up @@ -197,7 +196,7 @@ func (g *structGenerator) parseIndexesField(tags *structtag.Tags) error {

tag, err := validateFirestoreTag(tags)
if err != nil {
return xerrors.Errorf("firestora tag(%s) is invalid: %w", tag, err)
return xerrors.Errorf("firestore tag(%s) is invalid: %w", tag, err)
}

fieldInfo.FsTag = tag
Expand Down Expand Up @@ -257,18 +256,6 @@ func (g *structGenerator) parseTypeImpl(rawKey, firestoreKey string, obj *types.
continue
}

if !cont.Contains(supportedTypes, typeName) {
obj := strings.TrimPrefix(typeName, typeMap)

if !cont.Contains(supportedTypes, obj) {
log.Printf(
"%s: the type of `%s` is an invalid type in struct `%s` [%s]\n",
pos, e.RawName, g.structName, typeName,
)
continue
}
}

if strings.HasPrefix(typeName, "[]") {
g.param.SliceExist = true
}
Expand Down
28 changes: 17 additions & 11 deletions generator/testfiles/auto/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ import (

// Task ID自動生成あり
type Task struct {
ID string `firestore:"-" firestore_key:"auto"`
Desc string `firestore:"description" indexer:"e,p,s,l"`
Created time.Time `firestore:"created"`
Done bool `firestore:"done"`
Done2 bool `firestore:"done2"`
Count int `firestore:"count"`
Count64 int64 `firestore:"count64"`
NameList []string `firestore:"nameList"`
Proportion float64 `firestore:"proportion" indexer:"e"`
Flag map[string]float64 `firestore:"flag"`
Indexes map[string]bool `firestore:"indexes"`
ID string `firestore:"-" firestore_key:"auto"`
Desc string `firestore:"description" indexer:"e,p,s,l"`
Created time.Time `firestore:"created"`
Done bool `firestore:"done"`
Done2 bool `firestore:"done2"`
Count int `firestore:"count"`
Count64 int64 `firestore:"count64"`
NameList []string `firestore:"nameList"`
Proportion float64 `firestore:"proportion" indexer:"e"`
Flag map[string]float64 `firestore:"flag"`
SliceSubTask []*SubTask `firestore:"slice_sub_task"`
Indexes map[string]bool `firestore:"indexes"`
}

// SubTask - nested struct
type SubTask struct {
Name string `firestore:"name"`
}
Loading