From f7d778e0edac9089411ee4f212450942e1967390 Mon Sep 17 00:00:00 2001 From: Keson Date: Thu, 5 Nov 2020 18:12:23 +0800 Subject: [PATCH] fix duplicate alias (#183) --- tools/goctl/rpc/generator/gencall.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/goctl/rpc/generator/gencall.go b/tools/goctl/rpc/generator/gencall.go index 4afc1f04952d..c2c8fdcf47ab 100644 --- a/tools/goctl/rpc/generator/gencall.go +++ b/tools/goctl/rpc/generator/gencall.go @@ -5,6 +5,7 @@ import ( "path/filepath" "strings" + "github.com/tal-tech/go-zero/core/collection" "github.com/tal-tech/go-zero/tools/goctl/rpc/parser" "github.com/tal-tech/go-zero/tools/goctl/util" "github.com/tal-tech/go-zero/tools/goctl/util/stringx" @@ -79,15 +80,15 @@ func (g *defaultGenerator) GenCall(ctx DirContext, proto parser.Proto) error { return err } - var alias []string + var alias = collection.NewSet() for _, item := range service.RPC { - alias = append(alias, fmt.Sprintf("%s = %s", parser.CamelCase(item.RequestType), fmt.Sprintf("%s.%s", proto.PbPackage, parser.CamelCase(item.RequestType)))) - alias = append(alias, fmt.Sprintf("%s = %s", parser.CamelCase(item.ReturnsType), fmt.Sprintf("%s.%s", proto.PbPackage, parser.CamelCase(item.ReturnsType)))) + alias.AddStr(fmt.Sprintf("%s = %s", parser.CamelCase(item.RequestType), fmt.Sprintf("%s.%s", proto.PbPackage, parser.CamelCase(item.RequestType)))) + alias.AddStr(fmt.Sprintf("%s = %s", parser.CamelCase(item.ReturnsType), fmt.Sprintf("%s.%s", proto.PbPackage, parser.CamelCase(item.ReturnsType)))) } err = util.With("shared").GoFmt(true).Parse(text).SaveTo(map[string]interface{}{ "name": formatFilename(service.Name), - "alias": strings.Join(alias, util.NL), + "alias": strings.Join(alias.KeysStr(), util.NL), "head": head, "filePackage": formatFilename(service.Name), "package": fmt.Sprintf(`"%s"`, ctx.GetPb().Package),