51 lines
859 B
Go
51 lines
859 B
Go
package plug
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net"
|
|
|
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/graph"
|
|
pb "git.dragse.it/anthrove/plug-sdk/pkg/grpc"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
type Server struct {
|
|
ctx context.Context
|
|
address string
|
|
port string
|
|
database graph.OtterSpace
|
|
}
|
|
|
|
func NewServer(ctx context.Context, address string, port string) Server {
|
|
return Server{
|
|
ctx: ctx,
|
|
address: address,
|
|
port: port,
|
|
}
|
|
}
|
|
|
|
func (s Server) Listen() error {
|
|
var err error
|
|
|
|
lis, err := net.Listen("tcp", fmt.Sprintf("%s:%s", s.address, s.port))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
grpcServer := grpc.NewServer()
|
|
|
|
pb.RegisterPlugConnectorServer(grpcServer, NewGrpcServer(s.database))
|
|
|
|
err = grpcServer.Serve(lis)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s Server) WithGraphConnection(graph graph.OtterSpace) {
|
|
s.database = graph
|
|
}
|