use helper to detect import paths

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-02-23 23:54:53 +03:00
parent 8d4aac8b8b
commit 6b8fa89a69
6 changed files with 176 additions and 131 deletions

View File

@@ -14,28 +14,16 @@ func (g *Generator) microGenerate(component string, plugin *protogen.Plugin) err
}
gname := file.GeneratedFilenamePrefix + "_" + component + ".pb.go"
gfile := plugin.NewGeneratedFile(gname, ".")
gfile := plugin.NewGeneratedFile(gname, file.GoImportPath)
gfile.P("// Code generated by protoc-gen-micro")
gfile.P("// source: ", *file.Proto.Name)
gfile.P("package ", file.GoPackageName)
gfile.P()
gfile.P("import (")
gfile.P(`"context"`)
gfile.P()
gfile.P(`micro_api "github.com/unistack-org/micro/v3/api"`)
gfile.P(`micro_client "github.com/unistack-org/micro/v3/client"`)
gfile.P(")")
gfile.P()
gfile.P("// Reference imports to suppress errors if they are not otherwise used.")
gfile.P("var (")
gfile.P("_ ", "micro_api.Endpoint")
gfile.P("_ ", "context.Context")
gfile.P(" _ ", "micro_client.Option")
gfile.P(")")
gfile.P()
gfile.Import(contextPackage)
gfile.Import(microApiPackage)
gfile.Import(microClientPackage)
// generate services
for _, service := range file.Services {