package plug import ( "context" "fmt" "git.dragse.it/anthrove/otter-space-sdk/v2/pkg/database" "git.dragse.it/anthrove/otter-space-sdk/v2/pkg/models" "net" pb "git.dragse.it/anthrove/plug-sdk/pkg/grpc" "google.golang.org/grpc" ) type TaskExecution func(ctx context.Context, graph database.OtterSpace, sourceUsername string, anthroveUser models.User, deepScrape bool, cancelFunction func()) error type Server struct { address string port string ctx context.Context database database.OtterSpace taskExecutionFunction TaskExecution } 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, s.taskExecutionFunction)) err = grpcServer.Serve(lis) if err != nil { return err } return nil } func (s *Server) WithGraphConnection(graph database.OtterSpace) { s.database = graph } func (s *Server) TaskExecutionFunction(function TaskExecution) { s.taskExecutionFunction = function }