Skip to content

Commit

Permalink
Merge pull request #62 from TRON-US/BTFS-1156-DefaultController
Browse files Browse the repository at this point in the history
[BTFS-1156] - included default controller for guard services to register commander and preparer
  • Loading branch information
laipogo authored Jan 2, 2020
2 parents 36892be + 164c4d9 commit 308b0d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
5 changes: 5 additions & 0 deletions controller/defaultController.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package controller

type DefaultController struct {
ServerName string
}
23 changes: 13 additions & 10 deletions utils/grpc/setup_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package grpc

import (
"fmt"
"log"
"net"

"github.com/tron-us/go-btfs-common/protos/escrow"
Expand All @@ -11,7 +10,9 @@ import (
"github.com/tron-us/go-btfs-common/protos/shared"
"github.com/tron-us/go-btfs-common/protos/status"

"github.com/tron-us/go-btfs-common/controller"
"github.com/tron-us/go-common/v2/constant"
"github.com/tron-us/go-common/v2/log"
"github.com/tron-us/go-common/v2/middleware"

"go.uber.org/zap"
Expand All @@ -22,16 +23,16 @@ import (
)

type GrpcServer struct {
server *grpc.Server
healthServer *health.Server
serverName string
lis net.Listener
dBURL string
rDURL string
server *grpc.Server
healthServer *health.Server
serverName string
lis net.Listener
dBURL string
rDURL string
}

func (s *GrpcServer) serverTypeToServerName(server interface{}) {
switch server.(type) {
switch t := server.(type) {
case status.StatusServiceServer:
s.serverName = "status-server"
case escrow.EscrowServiceServer:
Expand All @@ -40,8 +41,8 @@ func (s *GrpcServer) serverTypeToServerName(server interface{}) {
s.serverName = "guard-interceptor"
case hub.HubQueryServiceServer:
s.serverName = "hub"
case string:
s.serverName = fmt.Sprintf("%v", server)
case *controller.DefaultController:
s.serverName = fmt.Sprintf("%v", t.ServerName)
default:
s.serverName = "unknown"
}
Expand Down Expand Up @@ -109,6 +110,8 @@ func (s *GrpcServer) RegisterServer(server interface{}) *GrpcServer {

shared.RegisterRuntimeServiceServer(s.server, &RuntimeServer{DB_URL: s.dBURL, RD_URL: s.rDURL, serviceName: s.serverName})

log.Info("Registered: " + s.serverName + " and runtime server!")

return s
}

Expand Down

0 comments on commit 308b0d5

Please sign in to comment.