Files
ark/asp/internal/interface/service.go
Louis Singer c8d9db89c5 Add interface layer (#23)
* implement grpc interface

* rework GetEventStream rpc

* implement Ping & GetEventStream

* remove dev_portal

* Compile protos

* Empty gitignore

---------

Co-authored-by: altafan <18440657+altafan@users.noreply.github.com>
2023-12-01 17:13:28 +01:00

50 lines
1.1 KiB
Go
Executable File

package interfaces
import (
arkv1 "github.com/ark-network/ark/api-spec/protobuf/gen/ark/v1"
"github.com/ark-network/ark/internal/core/application"
"github.com/ark-network/ark/internal/core/ports"
"github.com/ark-network/ark/internal/interface/grpc/handlers"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
// TODO: Edit this file to something more meaningful for your application.
type Service interface {
Start() error
Stop()
}
type service struct {
grpcService arkv1.ArkServiceServer
grpcServer *grpc.Server
}
type Options struct {
applicationService application.Service
repositoryManager ports.RepoManager
}
func NewService(opts Options) (Service, error) {
return &service{
grpcService: handlers.NewHandler(opts.applicationService, opts.repositoryManager),
}, nil
}
// Start implements Service.
func (s *service) Start() error {
creds := insecure.NewCredentials()
serverOpts := grpc.Creds(creds)
server := grpc.NewServer(serverOpts)
arkv1.RegisterArkServiceServer(server, s.grpcService)
s.grpcServer = server
return nil
}
// Stop implements Service.
func (s *service) Stop() {
s.grpcServer.Stop()
}