grpc_client.go 999 B

123456789101112131415161718192021222324252627
  1. package operation
  2. import (
  3. "google.golang.org/grpc"
  4. "github.com/chrislusf/seaweedfs/weed/pb"
  5. "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  6. "github.com/chrislusf/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, func(grpcConnection *grpc.ClientConn) error {
  10. client := volume_server_pb.NewVolumeServerClient(grpcConnection)
  11. return fn(client)
  12. }, volumeServer.ToGrpcAddress(), 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, func(grpcConnection *grpc.ClientConn) error {
  16. client := master_pb.NewSeaweedClient(grpcConnection)
  17. return fn(client)
  18. }, masterServer.ToGrpcAddress(), grpcDialOption)
  19. }