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

@@ -23,22 +23,18 @@ func (g *Generator) gorillaGenerate(component string, plugin *protogen.Plugin) e
gorillaPackageFiles[file.GoPackageName] = struct{}{}
gname := "micro" + "_" + component + ".pb.go"
gfile := plugin.NewGeneratedFile(gname, ".")
gfile := plugin.NewGeneratedFile(gname, file.GoImportPath)
gfile.P("// Code generated by protoc-gen-micro")
gfile.P("package ", file.GoPackageName)
gfile.P()
gfile.P("import (")
gfile.P(`"fmt"`)
gfile.P(`"net/http"`)
gfile.P(`"reflect"`)
gfile.P(`"strings"`)
gfile.P()
gfile.P(`micro_api "github.com/unistack-org/micro/v3/api"`)
gfile.P(`mux "github.com/gorilla/mux"`)
gfile.P(")")
gfile.P()
gfile.Import(fmtPackage)
gfile.Import(httpPackage)
gfile.Import(reflectPackage)
gfile.Import(stringsPackage)
gfile.Import(microApiPackage)
gfile.Import(gorillaMuxPackage)
gfile.P("func RegisterHandlers(r *mux.Router, h interface{}, eps []*micro_api.Endpoint) error {")
gfile.P("v := reflect.ValueOf(h)")