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 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"
)
// Define what Source this Plug is used for
source := models.Source{
DisplayName: "e621",
Domain: "e621.net",
Icon: "e621.net/icon.png",
}
func main() {
var ctx context.Context
// Create a new Plug instance
p := plug.NewPlug(ctx, "localhost", "50051", source)
// 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 OtterSpace database
p.WithOtterSpace(database)
// 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
if err := server.Listen(); err != nil {
log.Fatalf("Failed to listen: %v", err)
}
// 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)
}
func taskExecution(ctx context.Context, graph graph.OtterSpace, sourceUsername string, anthroveUser models.AnthroveUser, deepScrape bool, cancelFunction func()) error {
// SOME EXECUTION MAGIC
}
````