Skip to content

Commit

Permalink
fix(jzero): fix gensdk
Browse files Browse the repository at this point in the history
  • Loading branch information
jaronnie committed Jun 3, 2024
1 parent 6eb3b5b commit 3cde6f7
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
1 change: 1 addition & 0 deletions cmd/gensdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
1 change: 0 additions & 1 deletion docs/src/guide/gensdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ order: 5
* 链式调用, 调用逻辑清晰
* 自带 fake client 支持单元测试
* 可自定义接口进行扩展
* 支持基于统一 api 网关的多服务 sdk 集成在一个 sdk 库中

::: code-tabs#shell

Expand Down
4 changes: 3 additions & 1 deletion internal/gen/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 7 additions & 6 deletions internal/gensdk/config/config.go
Original file line number Diff line number Diff line change
@@ -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
}
28 changes: 15 additions & 13 deletions internal/gensdk/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/gensdk/generator/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 3cde6f7

Please sign in to comment.