Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一个进程启动grpc和gin时的swagger页面访问问题 #106

Closed
careyyoung opened this issue May 18, 2022 · 3 comments
Closed

一个进程启动grpc和gin时的swagger页面访问问题 #106

careyyoung opened this issue May 18, 2022 · 3 comments

Comments

@careyyoung
Copy link

Describe the bug
你好,
计划,一个boot.yaml,启动两个服务:grpc 和 gin,不同的 entryName
现在能启动,能通过不同的端口访问到 grpc 和 gin 的服务
但是,访问 sw 时,
只能 grpc 的 sw 正常,gin 的 sw 会提示:Failed to load API definition.
在控制台还会看到日志:2022/05/18 18:19:05 http: TLS handshake error from [::1]:12819: remote error: tls: unknown certificate

不过,访问 自定义的和common service 的路由 都是能正常访问的。
配置如下:

  1. boot.yaml
grpc:
  - name: grpc-api                                          # Required
    description: "grpc api"                         # Optional, default: ""
    enabled: true                                          # Required
    port: 58085                                             # Required
    sw:
      enabled: true                                        # Optional, default: false
gin:
  - name: rest-api
    port: 59095                    # 监听端口
    enabled: true                 # 开启 gin 微服务
    sw:
      enabled: true               # 开启 Swagger UI,默认路径为 /sw
  1. main.go
boot := rkboot.NewBoot()
ginEntry := rkgin.GetGinEntry("rest-api")
ginEntry.Router.GET("/api/v1/aa", restAPIHandler.GetAA)

// Get grpc entry with name
grpcEntry := rkgrpc.GetGrpcEntry("grpc-api")
boot.Bootstrap(context.Background())

Additional context
rk-boot/v2 v2.1.2
rk-entry/v2 v2.1.7
rk-gin/v2 v2.1.2
rk-grpc/v2 v2.1.6

谢谢。

@dongxuny
Copy link
Contributor

@careyyoung Hi, I will look at this problem~

@dongxuny
Copy link
Contributor

@careyyoung rk-boot 默认会从 api/gen/v1 和 docs/ 文件夹搜寻 swagger config 配置文件。在这个 Case 当中,Gin swagger UI 没有成功加载 Swagger Config 文件,可能是因为 swagger config 文件路径没找到,或者它从 proto 文件生成的时候,出现了一些兼容性问题(不过这种情况几乎不会出现)。

此外,TLS 错误这个问题,应该不是 rk-boot 的配置问题,因为你的 boot.yaml 里没有涉及到 TLS 相关配置。

我的猜想,应该是 swagger config 文件没有成功加载正确的配置文件。

我这里创建了一个例子,同时启动 Gin & gRPC,可以参考一下。
https://github.com/rookie-ninja/rk-demo/tree/master/grpc/v2/multiple-entry

另外,可以尝试一下在 boot.yaml 中,通过 sw.jsonPath 来指定 Swagger Config 文件所在的文件夹,来 Debug 是否依然不能成功加载。

举例:

grpc:
  - name: grpc-api
    enabled: true
    port: 8080
    enableReflection: true
    sw:
      enabled: true
      # define swagger config file path if we hope to use different one
      # jsonPath: ""
gin:
  - name: rest-api
    port: 8081
    enabled: true
    sw:
      enabled: true
      # define swagger config file path if we hope to use different one
      # jsonPath: ""

@dongxuny
Copy link
Contributor

@careyyoung Hi,上面的问题解决了吗?如果没有解决,请继续留下错误码和相关信息。

@dongxuny dongxuny closed this as completed Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants