This commit is contained in:
parent
7a508ece7e
commit
7d218b38ff
60
README.md
60
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)
|
||||
}
|
||||
|
||||
|
||||
````
|
||||
|
Reference in New Issue
Block a user