Skip to content

Commit

Permalink
refactor imports and extract variable
Browse files Browse the repository at this point in the history
  • Loading branch information
laipogo committed Dec 2, 2019
1 parent 9840766 commit b643c84
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions utils/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ import (
"crypto/tls"
"errors"
"fmt"
"net/url"
"regexp"
"strconv"
"strings"
"time"

"github.com/tron-us/go-btfs-common/protos/escrow"
"github.com/tron-us/go-btfs-common/protos/guard"
"github.com/tron-us/go-btfs-common/protos/hub"
"github.com/tron-us/go-btfs-common/protos/status"

"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/credentials"
"net/url"
"regexp"
"strconv"
"strings"
"time"
)

const (
Expand Down Expand Up @@ -44,15 +46,15 @@ func (g *ClientBuilder) doWithContext(ctx context.Context, f interface{}) error
if conn == nil || conn.GetState() != connectivity.Ready {
return errors.New("failed to get connection")
}
switch f.(type) {
switch v := f.(type) {
case func(context.Context, status.StatusClient) error:
return f.(func(context.Context, status.StatusClient) error)(ctx, status.NewStatusClient(conn))
return v(ctx, status.NewStatusClient(conn))
case func(context.Context, hub.HubQueryClient) error:
return f.(func(context.Context, hub.HubQueryClient) error)(ctx, hub.NewHubQueryClient(conn))
return v(ctx, hub.NewHubQueryClient(conn))
case func(context.Context, guard.GuardServiceClient) error:
return f.(func(context.Context, guard.GuardServiceClient) error)(ctx, guard.NewGuardServiceClient(conn))
return v(ctx, guard.NewGuardServiceClient(conn))
case func(context.Context, escrow.EscrowServiceClient) error:
return f.(func(context.Context, escrow.EscrowServiceClient) error)(ctx, escrow.NewEscrowServiceClient(conn))
return v(ctx, escrow.NewEscrowServiceClient(conn))
default:
return fmt.Errorf("illegal function: %T", f)
}
Expand Down

0 comments on commit b643c84

Please sign in to comment.