directclient.go 504 B

1234567891011121314151617181920212223242526
  1. package internal
  2. import (
  3. "google.golang.org/grpc"
  4. "google.golang.org/grpc/balancer/roundrobin"
  5. )
  6. type DirectClient struct {
  7. conn *grpc.ClientConn
  8. }
  9. func NewDirectClient(server string, opts ...ClientOption) (*DirectClient, error) {
  10. opts = append(opts, WithDialOption(grpc.WithBalancerName(roundrobin.Name)))
  11. conn, err := dial(server, opts...)
  12. if err != nil {
  13. return nil, err
  14. }
  15. return &DirectClient{
  16. conn: conn,
  17. }, nil
  18. }
  19. func (c *DirectClient) Conn() *grpc.ClientConn {
  20. return c.conn
  21. }