V2 #2

Merged
fenpaws merged 13 commits from V2 into main 2024-07-08 13:42:14 +00:00
Showing only changes of commit 7d218b38ff - Show all commits

View File

@ -1,6 +1,6 @@
# Anthrove Plug SDK # 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 ## Installation
@ -14,40 +14,36 @@ go get git.dragse.it/anthrove/plug-sdk
Below is a basic example of how to use the SDK: Below is a basic example of how to use the SDK:
````go ````go
package main import "git.dragse.it/anthrove/plug-sdk/v2/pkg/plug"
import ( // Define what Source this Plug is used for
"context" source := models.Source{
"git.dragse.it/anthrove/plug-sdk/pkg/otter" DisplayName: "e621",
"log" Domain: "e621.net",
"net" Icon: "e621.net/icon.png",
"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() { // Create a new Plug instance
var ctx context.Context p := plug.NewPlug(ctx, "localhost", "50051", source)
// Initialize a new server // Set the OtterSpace database
server := plug.NewServer(ctx, "localhost", "8080") p.WithOtterSpace(database)
graph := otter.ConnectToDatabase(ctx, "endpoint", "username", "password", false)
// Set the graph database connection
server.WithGraphConnection(graph)
// Set the task execution function // Set the task execution function
server.TaskExecutionFunction(taskExecution) 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
})
// Listen for connections // Set the send message execution function
if err := server.Listen(); err != nil { p.SendMessageExecution(func(ctx context.Context, userSourceID string, message string) error {
log.Fatalf("Failed to listen: %v", err) // Your message sending logic here
} })
// Start the server
err := p.Listen()
if err != nil {
log.Fatalf("Failed to start server: %v", err)
} }
func taskExecution(ctx context.Context, graph graph.OtterSpace, sourceUsername string, anthroveUser models.AnthroveUser, deepScrape bool, cancelFunction func()) error {
// SOME EXECUTION MAGIC
}
```` ````