Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions cmd/jzero/internal/command/gen/genswagger/genswagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,18 @@ func Gen() (err error) {
pluginName := getPluginNameFromFilePath(v)
if pluginName != "" {
// 插件文件处理:找到 desc/api 在路径中的位置
descApiIndex := strings.Index(v, "/desc/api/")
descApiPath := filepath.Join("desc", "api") + string(filepath.Separator)
descApiIndex := strings.Index(v, descApiPath)
var pluginApiDir string
if descApiIndex == -1 {
// 如果找不到 /desc/api/ 模式,尝试查找路径末尾是否以 desc/api 结尾
if strings.HasSuffix(filepath.Dir(v), "/desc/api") {
// 如果找不到 desc/api 模式,尝试查找路径末尾是否以 desc/api 结尾
if strings.HasSuffix(filepath.Dir(v), filepath.Join("desc", "api")) {
pluginApiDir = filepath.Dir(v)
} else {
return fmt.Errorf("invalid plugin api path: %s", v)
}
} else {
pluginApiDir = v[:descApiIndex+len("/desc/api")]
pluginApiDir = v[:descApiIndex+len(descApiPath)]
}

var relErr error
Expand All @@ -127,7 +128,7 @@ func Gen() (err error) {
return relErr
}
// 在插件目录下保持结构
relPath = "plugins/" + pluginName + "/" + relPath
relPath = filepath.Join("plugins", pluginName, relPath)
} else {
// 普通 API 文件处理
relPath, err = filepath.Rel(config.C.ApiDir(), v)
Expand Down
42 changes: 28 additions & 14 deletions cmd/jzero/internal/desc/desc.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,44 @@ func GetFrameType() (string, error) {
// rpc 项目
frameType = "rpc"

// 获取全量 proto 文件
protoFiles, err := FindRpcServiceProtoFiles(config.C.ProtoDir())
if err != nil {
return "", err
}

for _, v := range protoFiles {
// parse proto
protoParser := rpcparser.NewDefaultProtoParser()
var parse rpcparser.Proto
parse, err = protoParser.Parse(v, true)
// 检查是否是 gateway 项目(优先检查 cmd/server.go)
if isGatewayProject() {
frameType = "gateway"
} else {
// 获取全量 proto 文件
protoFiles, err := FindRpcServiceProtoFiles(config.C.ProtoDir())
if err != nil {
return "", err
}
if IsNeedGenProtoDescriptor(parse) {
frameType = "gateway"
break

for _, v := range protoFiles {
// parse proto
protoParser := rpcparser.NewDefaultProtoParser()
var parse rpcparser.Proto
parse, err = protoParser.Parse(v, true)
if err != nil {
return "", err
}
if IsNeedGenProtoDescriptor(parse) {
frameType = "gateway"
break
}
}
}
}

return frameType, nil
}

// isGatewayProject 检查 third_party/grpc-gateway 目录是否存在
func isGatewayProject() bool {
grpcGatewayPath := filepath.Join(config.C.ProtoDir(), "third_party", "grpc-gateway")
if _, err := os.Stat(grpcGatewayPath); err == nil {
return true
}
return false
}

func GetProtoDescriptorPath(protoPath string) string {
rel, err := filepath.Rel(filepath.Join("desc", "proto"), protoPath)
if err != nil {
Expand Down
Loading