diff --git a/cmd/gensdk.go b/cmd/gensdk.go index c8169475..a2058287 100644 --- a/cmd/gensdk.go +++ b/cmd/gensdk.go @@ -36,6 +36,7 @@ func init() { genSdkCmd.Flags().StringVarP(&gensdk.ApiDir, "api-dir", "", filepath.Join("desc", "api"), "set input api dir") genSdkCmd.Flags().StringVarP(&gensdk.ProtoDir, "proto-dir", "", filepath.Join("desc", "proto"), "set input proto dir") + genSdkCmd.Flags().BoolVarP(&gensdk.WarpResponse, "warp-response", "", false, "warp response: code, data, message") genSdkCmd.Flags().StringVarP(&gensdk.Scope, "scope", "", "", "set scope name") genSdkCmd.Flags().StringVarP(&embeded.Home, "home", "", "", "set template home") } diff --git a/docs/src/guide/gensdk.md b/docs/src/guide/gensdk.md index 3896f048..6f8aed5e 100644 --- a/docs/src/guide/gensdk.md +++ b/docs/src/guide/gensdk.md @@ -11,7 +11,6 @@ order: 5 * 链式调用, 调用逻辑清晰 * 自带 fake client 支持单元测试 * 可自定义接口进行扩展 -* 支持基于统一 api 网关的多服务 sdk 集成在一个 sdk 库中 ::: code-tabs#shell diff --git a/internal/gen/common.go b/internal/gen/common.go index 168ffc37..eb27641b 100644 --- a/internal/gen/common.go +++ b/internal/gen/common.go @@ -29,7 +29,9 @@ func GetProtoFilenames(protoDirPath string) ([]string, error) { if protoFile.IsDir() { continue } - protoFilenames = append(protoFilenames, protoFile.Name()) + if strings.HasSuffix(protoFile.Name(), ".proto") { + protoFilenames = append(protoFilenames, protoFile.Name()) + } } return protoFilenames, nil } diff --git a/internal/gensdk/config/config.go b/internal/gensdk/config/config.go index 25e98ef4..50e18c26 100644 --- a/internal/gensdk/config/config.go +++ b/internal/gensdk/config/config.go @@ -1,10 +1,11 @@ package config type Config struct { - Language string - APP string - Module string - Dir string // output dir - ApiDir string - ProtoDir string + Language string + APP string + Module string + Dir string // output dir + ApiDir string + ProtoDir string + WarpResponse bool } diff --git a/internal/gensdk/gen.go b/internal/gensdk/gen.go index 059d40cb..3a9cab18 100644 --- a/internal/gensdk/gen.go +++ b/internal/gensdk/gen.go @@ -13,13 +13,14 @@ import ( ) var ( - Scope string - ApiDir string - ProtoDir string - Dir string - WorkingDir string - Language string - Module string + Scope string + ApiDir string + ProtoDir string + WarpResponse bool + Dir string + WorkingDir string + Language string + Module string Version string ) @@ -46,12 +47,13 @@ func GenSdk(_ *cobra.Command, _ []string) error { } c := config.Config{ - Language: Language, - APP: Scope, - Module: Module, - Dir: Dir, - ApiDir: ApiDir, - ProtoDir: ProtoDir, + Language: Language, + APP: Scope, + Module: Module, + Dir: Dir, + ApiDir: ApiDir, + ProtoDir: ProtoDir, + WarpResponse: WarpResponse, } gen, err := generator.New(c) diff --git a/internal/gensdk/generator/golang.go b/internal/gensdk/generator/golang.go index eefdcc77..9c3433d8 100644 --- a/internal/gensdk/generator/golang.go +++ b/internal/gensdk/generator/golang.go @@ -319,7 +319,7 @@ func (g *Golang) genScopeResources(rhis vars.ScopeResourceHTTPInterfaceMap, scop "Scope": scope, "Resource": resource, "HTTPInterfaces": rhis[vars.Scope(scope)][vars.Resource(resource)], - "IsWarpHTTPResponse": true, + "IsWarpHTTPResponse": g.config.WarpResponse, "GoImportPaths": g.genImports(rhis[vars.Scope(scope)][vars.Resource(resource)]), }, embeded.ReadTemplateFile(filepath.Join("client", "client-go", "typed", "resource.go.tpl"))) if err != nil { @@ -375,7 +375,7 @@ func (g *Golang) genPbTypesModel() ([]*GeneratedFile, error) { } defer os.RemoveAll(tmpDir) - resp, err := execx.Run(fmt.Sprintf("protoc -I./app/desc/proto --go_out=%s app/desc/proto/*.proto", tmpDir), g.wd) + resp, err := execx.Run(fmt.Sprintf("protoc -I%s --go_out=%s %s/*.proto", g.config.ProtoDir, tmpDir, g.config.ProtoDir), g.wd) if err != nil { return nil, errors.Errorf("err: [%v], resp: [%s]", err, resp) }