This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
plug-sdk/pkg/plug/server.go
2024-02-20 19:11:34 +01:00

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
}