rpc_api.go 629 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. * @description: rpc 实例
  3. * @Author: CP
  4. * @Date: 2020-11-12 22:49:59
  5. * @FilePath: \construction_management\web\api\rpc_api.go
  6. */
  7. package api
  8. import (
  9. "github.com/kataras/iris/v12"
  10. "go.mod/services"
  11. "google.golang.org/grpc"
  12. )
  13. type RpcApi struct {
  14. //框架-web应用上下文环境
  15. Ctx iris.Context
  16. // 需要用的service
  17. ServiceRpc services.RpcService
  18. }
  19. // func (c *RpcApi) BeforeActivation(b mvc.BeforeActivation) {
  20. // fmt.Println("dd")
  21. // }
  22. // 实例1 RpcConnect *grpc.ClientConn
  23. func (c *RpcApi) Get() {
  24. RpcConnect := c.Ctx.Values().Get("RpcConnect").(*grpc.ClientConn)
  25. c.ServiceRpc.Test(RpcConnect)
  26. }