-
Notifications
You must be signed in to change notification settings - Fork 12
Modules
Christopher McGregor edited this page Feb 16, 2018
·
35 revisions
Modules "building blocks" that integrate with Disgo by implementing the interface IService located in the disgo_commons repo.
// IService
type IService interface {
Name() string
IsRunning() bool
RegisterGrpc(grpcServer *grpc.Server)
Go(waitGroup *sync.WaitGroup)
}
- Name() returns the name of the service
- IsRunning() returns if the service is still running
- RegisterGrpc(listener *net.Listener) allows for the service to register GRPC server on an existing listening port
- Go(waitGroup *sync.WaitGroup) is the main entry point of the service
The following is a shell implementation of the DAPoS service DAPoS service:
package core
import (
"sync"
"google.golang.org/grpc"
"context"
"github.com/dispatchlabs/dapos/proto"
log "github.com/sirupsen/logrus"
)
// DAPoSService
type DAPoSService struct {
running bool
}
// NewDAPoSService
func NewDAPoSService() *DAPoSService {
return &DAPoSService{
running: false,
}
}
// Init
func (daposService *DAPoSService) Init() {
log.WithFields(log.Fields{
"method": "DAPoSService.Init",
}).Info("init...")
}
// Name
func (daposService *DAPoSService) Name() string {
return "DAPoSService"
}
// IsRunning
func (daposService *DAPoSService) IsRunning() bool {
return daposService.running
}
// Register
func (daposService *DAPoSService) RegisterGrpc(grpcServer *grpc.Server) {
proto.RegisterDAPoSGrpcServer(grpcServer, daposService)
}
// Go
func (daposService *DAPoSService) Go(waitGroup *sync.WaitGroup) {
daposService.running = true
}
// BroadcastTransaction
func (daposService *DAPoSService) BroadcastTransaction(context.Context, *proto.Transaction) (*proto.TransactionResponse, error) {
return nil, nil
}
// ReceiveTransaction
func (daposService *DAPoSService) ReceiveTransaction(context.Context, *proto.Transaction) (*proto.TransactionResponse, error) {
return nil, nil
}