grpc_client.go 1019 B

123456789101112131415161718192021222324252627
  1. package operation
  2. import (
  3. "google.golang.org/grpc"
  4. "github.com/seaweedfs/seaweedfs/weed/pb"
  5. "github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
  6. "github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
  7. )
  8. func WithVolumeServerClient(streamingMode bool, volumeServer pb.ServerAddress, grpcDialOption grpc.DialOption, fn func(volume_server_pb.VolumeServerClient) error) error {
  9. return pb.WithGrpcClient(streamingMode, 0, func(grpcConnection *grpc.ClientConn) error {
  10. client := volume_server_pb.NewVolumeServerClient(grpcConnection)
  11. return fn(client)
  12. }, volumeServer.ToGrpcAddress(), false, grpcDialOption)
  13. }
  14. func WithMasterServerClient(streamingMode bool, masterServer pb.ServerAddress, grpcDialOption grpc.DialOption, fn func(masterClient master_pb.SeaweedClient) error) error {
  15. return pb.WithGrpcClient(streamingMode, 0, func(grpcConnection *grpc.ClientConn) error {
  16. client := master_pb.NewSeaweedClient(grpcConnection)
  17. return fn(client)
  18. }, masterServer.ToGrpcAddress(), false, grpcDialOption)
  19. }