Skip to content

Commit

Permalink
test ok
Browse files Browse the repository at this point in the history
  • Loading branch information
turingczz committed Jul 15, 2022
1 parent 778e6e3 commit 8d23c2e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ PG_FIX_CANDIDATES=./protos/node/node.pb.go \
./protos/status/status.pb.go \
./protos/escrow/escrow.pb.go \
./protos/guard/guard.pb.go \
./protos/online/online.pb.go \

install: brew trongogo

Expand Down
3 changes: 3 additions & 0 deletions utils/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"errors"
"fmt"
"github.com/tron-us/go-btfs-common/protos/online"
"net/url"
"strconv"
"strings"
Expand Down Expand Up @@ -50,6 +51,8 @@ func (g *ClientBuilder) doWithContext(ctx context.Context, f interface{}) error
return err
}
switch v := f.(type) {
case func(context.Context, online.OnlineServiceClient) error:
return wrapError("OnlineClient", v(ctx, online.NewOnlineServiceClient(conn)))
case func(context.Context, statuspb.StatusServiceClient) error:
return wrapError("StatusClient", v(ctx, statuspb.NewStatusServiceClient(conn)))
case func(context.Context, hubpb.HubQueryServiceClient) error:
Expand Down
19 changes: 19 additions & 0 deletions utils/grpc/online.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package grpc

import (
"context"
"github.com/tron-us/go-btfs-common/protos/online"
)

func OnlineClient(addr string) *OnlineClientBuilder {
return &OnlineClientBuilder{builder(addr)}
}

type OnlineClientBuilder struct {
ClientBuilder
}

func (g *OnlineClientBuilder) WithContext(ctx context.Context, f func(ctx context.Context,
client online.OnlineServiceClient) error) error {
return g.doWithContext(ctx, f)
}
5 changes: 5 additions & 0 deletions utils/grpc/setup_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package grpc
import (
"context"
"fmt"
"github.com/tron-us/go-btfs-common/protos/online"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -55,6 +56,8 @@ type GrpcServer struct {

func (s *GrpcServer) serverTypeToServerName(server interface{}) {
switch t := server.(type) {
case online.OnlineServiceServer:
s.serverName = "online-server"
case status.StatusServiceServer:
s.serverName = "status-server"
case escrow.EscrowServiceServer:
Expand Down Expand Up @@ -173,6 +176,8 @@ func (s *GrpcServer) CreateHealthServer() *GrpcServer {
func (s *GrpcServer) RegisterServer(server interface{}) *GrpcServer {

switch server.(type) {
case online.OnlineServiceServer:
online.RegisterOnlineServiceServer(s.server, server.(online.OnlineServiceServer))
case status.StatusServiceServer:
status.RegisterStatusServiceServer(s.server, server.(status.StatusServiceServer))
case escrow.EscrowServiceServer:
Expand Down

0 comments on commit 8d23c2e

Please sign in to comment.