Skip to content

Commit dccddc4

Browse files
committed
Rename types
1 parent cada48c commit dccddc4

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

pkg/inserter/js_inserter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (j *JSInserter) Execute(ctx context.Context, cn, path string) error {
5454
return xerrors.Errorf("failed to marshal json of returned value: %w", err)
5555
}
5656

57-
jms := make([]ModelItem, 0)
57+
jms := make([]Document, 0)
5858
err = json.Unmarshal(jb, &jms)
5959
if err != nil {
6060
return xerrors.Errorf("failed to unmarshal json: %w", err)
@@ -71,7 +71,7 @@ func (j *JSInserter) Execute(ctx context.Context, cn, path string) error {
7171

7272
//nolint:dupl
7373
// CreateItem - Firestore にアイテムを生成する
74-
func (j *JSInserter) CreateItem(ctx context.Context, path []string, items []ModelItem, collectionIndexes []int) error {
74+
func (j *JSInserter) CreateItem(ctx context.Context, path []string, items []Document, collectionIndexes []int) error {
7575
for idx, parentItem := range items {
7676
nowIndexes := append(collectionIndexes, idx)
7777
docPath := strings.Join(path, "/")
@@ -87,7 +87,7 @@ func (j *JSInserter) CreateItem(ctx context.Context, path []string, items []Mode
8787
continue
8888
}
8989
for collectionName, subItems := range parentItem.SubCollections {
90-
err := j.CreateItem(ctx, append(path, j.ci.refIDs[parentItem.Ref], collectionName), subItems, nowIndexes)
90+
err := j.CreateItem(ctx, append(path, j.ci.refIDs[parentItem.Ref], string(collectionName)), subItems, nowIndexes)
9191
if err != nil {
9292
return xerrors.Errorf("failed to create item in array: %w", err)
9393
}

pkg/inserter/json_inserter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (j *JSONInserter) Execute(ctx context.Context, cn, path string) error {
3030
return xerrors.Errorf("failed to read json file: %+v", err)
3131
}
3232

33-
jm := new(Model)
33+
jm := new(Collection)
3434
err = json.Unmarshal(jb, jm)
3535
if err != nil {
3636
return xerrors.Errorf("failed to unmarshal json: %w", err)
@@ -47,7 +47,7 @@ func (j *JSONInserter) Execute(ctx context.Context, cn, path string) error {
4747

4848
//nolint:dupl
4949
// CreateItem - Firestore にアイテムを生成する
50-
func (j *JSONInserter) CreateItem(ctx context.Context, path []string, items []ModelItem, collectionIndexes []int) error {
50+
func (j *JSONInserter) CreateItem(ctx context.Context, path []string, items []Document, collectionIndexes []int) error {
5151
for idx, parentItem := range items {
5252
nowIndexes := append(collectionIndexes, idx)
5353
docPath := strings.Join(path, "/")
@@ -63,7 +63,7 @@ func (j *JSONInserter) CreateItem(ctx context.Context, path []string, items []Mo
6363
continue
6464
}
6565
for collectionName, subItems := range parentItem.SubCollections {
66-
err := j.CreateItem(ctx, append(path, j.ci.refIDs[parentItem.Ref], collectionName), subItems, nowIndexes)
66+
err := j.CreateItem(ctx, append(path, j.ci.refIDs[parentItem.Ref], string(collectionName)), subItems, nowIndexes)
6767
if err != nil {
6868
return xerrors.Errorf("failed to create item in array: %w", err)
6969
}

pkg/inserter/model.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package inserter
22

3-
// Model - JSONやYAMLのモデル
4-
type Model struct {
3+
type CollectionName string
4+
5+
// Collection - JSONやYAMLのモデル
6+
type Collection struct {
57
Version string `json:"version" yaml:"version"`
6-
Items []ModelItem `json:"items" yaml:"version"`
8+
Items []Document `json:"items" yaml:"version"`
79
}
810

9-
// ModelItem - Modelが持つアイテム
10-
type ModelItem struct {
11+
// Document - Modelが持つアイテム
12+
type Document struct {
1113
Ref string `json:"ref" yaml:"ref"`
1214
Payload map[string]interface{} `json:"payload" yaml:"payload"`
13-
SubCollections map[string][]ModelItem `json:"sub_collections"`
15+
SubCollections map[CollectionName][]Document `json:"sub_collections"`
1416
}

pkg/inserter/yaml_inserter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (y *YAMLInserter) Execute(ctx context.Context, cn, path string) error {
2727
return xerrors.Errorf("failed to read yaml file: %+v", err)
2828
}
2929

30-
ym := new(Model)
30+
ym := new(Collection)
3131
err = yaml.Unmarshal(yb, ym)
3232
if err != nil {
3333
return xerrors.Errorf("failed to unmarshal yaml: %w", err)

0 commit comments

Comments
 (0)