From 7d218b38ffd63fa5f705b5d8685da93293a7766f Mon Sep 17 00:00:00 2001 From: David Janowski Date: Mon, 8 Jul 2024 15:25:26 +0200 Subject: [PATCH] docs: updated readme --- README.md | 60 ++++++++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 95ba089..bcdee5a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Anthrove Plug SDK -Anthrove Plug SDK is a Golang-based Software Development Kit (SDK) that provides a gRPC server implementation for the Anthrove system. This SDK enables users to easily set up a server, establish a graph database connection, and set a task execution function. +Anthrove Plug SDK is a Golang-based Software Development Kit (SDK) that provides a gRPC server implementation for the Anthrove system. This SDK enables users to easily set up a server, establish a database connection, and set a task execution function. ## Installation @@ -14,40 +14,36 @@ go get git.dragse.it/anthrove/plug-sdk Below is a basic example of how to use the SDK: ````go -package main +import "git.dragse.it/anthrove/plug-sdk/v2/pkg/plug" -import ( - "context" - "git.dragse.it/anthrove/plug-sdk/pkg/otter" - "log" - "net" - "git.dragse.it/anthrove/otter-space-sdk/pkg/graph" - "git.dragse.it/anthrove/otter-space-sdk/pkg/models" - "git.dragse.it/anthrove/plug-sdk/pkg/plug" -) - -func main() { - var ctx context.Context - - // Initialize a new server - server := plug.NewServer(ctx, "localhost", "8080") - - graph := otter.ConnectToDatabase(ctx, "endpoint", "username", "password", false) - - // Set the graph database connection - server.WithGraphConnection(graph) - - // Set the task execution function - server.TaskExecutionFunction(taskExecution) - - // Listen for connections - if err := server.Listen(); err != nil { - log.Fatalf("Failed to listen: %v", err) - } +// Define what Source this Plug is used for +source := models.Source{ + DisplayName: "e621", + Domain: "e621.net", + Icon: "e621.net/icon.png", } -func taskExecution(ctx context.Context, graph graph.OtterSpace, sourceUsername string, anthroveUser models.AnthroveUser, deepScrape bool, cancelFunction func()) error { - // SOME EXECUTION MAGIC +// Create a new Plug instance +p := plug.NewPlug(ctx, "localhost", "50051", source) + +// Set the OtterSpace database +p.WithOtterSpace(database) + +// Set the task execution function +p.TaskExecutionFunction(func(ctx context.Context, database database.OtterSpace, sourceUsername string, anthroveUser models.User, deepScrape bool, apiKey string, cancelFunction func()) error { +// Your task execution logic here +}) + +// Set the send message execution function +p.SendMessageExecution(func(ctx context.Context, userSourceID string, message string) error { +// Your message sending logic here +}) + +// Start the server +err := p.Listen() + if err != nil { + log.Fatalf("Failed to start server: %v", err) } + ````