1

I am working in golang for the first time and am trying to convert a variable of type *grpcpool.ClientConn to *grpc.ClientConn.

I would like to pass the variable to a function that only takes *grpc.ClientConn. I am using a grpc client stub which requires the *grpc.ClientConn type and I am using processout/grpc-go-pool for the grpc pooling library. I looked at the possibility of making use of Factory in pool.go, but am pretty stuck since that is a type that returns a *grpc.ClientConn.

Does anyone have any suggestions as to how I might be able to make that conversion?

1 Answers1

2

I mean the grpcpool.ClientConn struct is just:

https://godoc.org/github.com/processout/grpc-go-pool#ClientConn

type ClientConn struct {
    *grpc.ClientConn
    // contains filtered or unexported fields
}

So I'm fairly certain you can just do:

pool := &grpcPool.ClientConn{} // however you get one of these
SomeFunc(pool.ClientConn)

See https://play.golang.org/p/YEzy4Wq8WF9 as an example of getting the embedded struct

dave
  • 62,300
  • 5
  • 72
  • 93
  • Thank you so much that made me realize that I was thinking about part of the pool.go file incorrectly. I really appreciate your comment! – user13895177 Jul 09 '20 at 01:18