diff --git a/langs/go/go.go b/langs/go/go.go index 6209ef0..d592b35 100644 --- a/langs/go/go.go +++ b/langs/go/go.go @@ -20,6 +20,14 @@ const ( fileExtension = ".firemodel.go" ) +var ( + importNames = map[string]string{ + "github.com/visor-tax/firemodel/runtime": "runtime", + "google.golang.org/genproto/googleapis/type/latlng": "latlng", + "cloud.google.com/go/firestore": "firestore", + } +) + type GoModeler struct { pkg string clientNames []*ClientName @@ -58,6 +66,7 @@ func (m *GoModeler) Model(schema *firemodel.Schema, sourceCoder firemodel.Source func (m *GoModeler) writeManifest(sourceCoder firemodel.SourceCoder) error { f := jen.NewFile(m.packageName()) + f.ImportNames(importNames) f.HeaderComment(fmt.Sprintf("DO NOT EDIT - Code generated by firemodel %s.", version.Version)) f.Type().Id("Client").StructFunc(func(g *jen.Group) { @@ -94,6 +103,7 @@ func (m *GoModeler) writeManifest(sourceCoder firemodel.SourceCoder) error { func (m *GoModeler) writeModel(model *firemodel.SchemaModel, sourceCoder firemodel.SourceCoder) error { f := jen.NewFile(m.packageName()) + f.ImportNames(importNames) f.HeaderComment(fmt.Sprintf("DO NOT EDIT - Code generated by firemodel %s.", version.Version)) if model.Comment != "" { @@ -344,6 +354,7 @@ func (m *GoModeler) writeModel(model *firemodel.SchemaModel, sourceCoder firemod func (m *GoModeler) writeEnum(enum *firemodel.SchemaEnum, sourceCoder firemodel.SourceCoder) error { enumName := strcase.ToCamel(enum.Name) f := jen.NewFile(m.packageName()) + f.ImportNames(importNames) f.HeaderComment(fmt.Sprintf("DO NOT EDIT - Code generated by firemodel %s.", version.Version)) if enum.Comment != "" { @@ -393,6 +404,7 @@ func (m *GoModeler) writeEnum(enum *firemodel.SchemaEnum, sourceCoder firemodel. func (m *GoModeler) writeStruct(structType *firemodel.SchemaStruct, sourceCoder firemodel.SourceCoder) error { structName := strcase.ToCamel(structType.Name) f := jen.NewFile(m.packageName()) + f.ImportNames(importNames) f.HeaderComment(fmt.Sprintf("DO NOT EDIT - Code generated by firemodel %s.", version.Version)) if structType.Comment != "" { diff --git a/testfixtures/firemodel/TestFiremodelFromSchema/go/module.go b/testfixtures/firemodel/TestFiremodelFromSchema/go/module.go index c1ea5dc..2d43156 100644 --- a/testfixtures/firemodel/TestFiremodelFromSchema/go/module.go +++ b/testfixtures/firemodel/TestFiremodelFromSchema/go/module.go @@ -2,7 +2,7 @@ package firemodel -import firestore "cloud.google.com/go/firestore" +import "cloud.google.com/go/firestore" type Client struct { Client *firestore.Client diff --git a/testfixtures/firemodel/TestFiremodelFromSchema/go/test_model.firemodel.go b/testfixtures/firemodel/TestFiremodelFromSchema/go/test_model.firemodel.go index 634f3bd..055d5f9 100644 --- a/testfixtures/firemodel/TestFiremodelFromSchema/go/test_model.firemodel.go +++ b/testfixtures/firemodel/TestFiremodelFromSchema/go/test_model.firemodel.go @@ -3,12 +3,12 @@ package firemodel import ( - firestore "cloud.google.com/go/firestore" + "cloud.google.com/go/firestore" "context" "errors" "fmt" - runtime "github.com/visor-tax/firemodel/runtime" - latlng "google.golang.org/genproto/googleapis/type/latlng" + "github.com/visor-tax/firemodel/runtime" + "google.golang.org/genproto/googleapis/type/latlng" "regexp" "time" ) diff --git a/testfixtures/firemodel/TestFiremodelFromSchema/go/test_timestamps.firemodel.go b/testfixtures/firemodel/TestFiremodelFromSchema/go/test_timestamps.firemodel.go index c065f90..dd5cd3e 100644 --- a/testfixtures/firemodel/TestFiremodelFromSchema/go/test_timestamps.firemodel.go +++ b/testfixtures/firemodel/TestFiremodelFromSchema/go/test_timestamps.firemodel.go @@ -3,7 +3,7 @@ package firemodel import ( - firestore "cloud.google.com/go/firestore" + "cloud.google.com/go/firestore" "context" "errors" "fmt"