This repository has been archived on 2024-11-27. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
SoXX 6c5e7089e6
All checks were successful
Gitea Build Check / Build (pull_request) Successful in 43s
Update README.md
2024-11-27 18:53:09 +00:00
.gitea/workflows migration from old git (no git history) 2024-07-19 15:28:48 +02:00
pkg fix(algorithm): CreatedAt 2024-11-14 22:02:06 +01:00
scripts fix: wrong user 2024-08-26 16:50:25 +02:00
third_party feat: add submodules correct 2024-08-25 01:48:27 +02:00
tools fix(dependencies): removed unneeded ones 2024-11-14 22:04:01 +01:00
.gitignore feat(testing): added e621 plug capabilities 2024-11-14 22:01:19 +01:00
.gitmodules feat: add submodules correct 2024-08-25 01:48:27 +02:00
go.mod fix(dependencies): removed unneeded ones 2024-11-14 22:04:01 +01:00
go.sum fix(dependencies): removed unneeded ones 2024-11-14 22:04:01 +01:00
README.md Update README.md 2024-11-27 18:53:09 +00:00
sonar-project.properties fix: wrong user 2024-08-26 16:50:25 +02:00

DEPRICATED: THIS PLUG GOT MERGED WITH THE NEW PLUG-NGX

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 database connection, and set a task execution function.

Installation

To install the Anthrove Plug SDK, you will need to have Go installed on your system. You can then use the go get command to fetch the SDK:

go get git.anthrove.art/Anthrove/plug-sdk/v5

Usage

Below is a basic example of how to use the SDK:

proposed Plug structure

your-project/
│
├── cmd
│   └── your-plug
│       └── main.go
├── config
├── internal
│   ├── service
│   └── utils
└── go.mod

config.go


package config

import (
	"fmt"

	"github.com/caarlos0/env/v10"
	"github.com/go-playground/validator/v10"
)

type CoreConfig struct {
	LogLevel  string `env:"LOG_LEVEL" envDefault:"INFO" validate:"eq_ignore_case=FATAL|eq_ignore_case=ERROR|eq_ignore_case=WARN|eq_ignore_case=INFO|eq_ignore_case=DEBUG|eq_ignore_case=TRACE"`
	LogFormat string `env:"LOG_FORMAT" envDefault:"PLAIN" validate:"eq_ignore_case=PLAIN|eq_ignore_case=JSON"`
}

type PlugConfig struct {
	PlugDomain      string `env:"PLUG_DOMAIN" envDefault:"e621.net"`
	PlugIcon        string `env:"PLUG_ICON" envDefault:"https://e621.net/safari-pinned-tab.svg"`
	PlugDisplayName string `env:"PLUG_DISPLAY_NAME" envDefault:"e621.net"`
	PlugAPIKey      string `env:"PLUG_API_KEY,required"`
	PlugUsername    string `env:"PLUG_USERNAME,required"`
}

// LoadConfig loads the configuration from environment variables and validates it.
func LoadConfig[T any](cfg T) (T, error) {

	if err := env.Parse(&cfg); err != nil {
		return cfg, fmt.Errorf("config: error parsing configuration: %w", err)
	}

	validate := validator.New()
	if err := validate.Struct(cfg); err != nil {
		return cfg, fmt.Errorf("config: validation error: %w", err)
	}

	return cfg, nil
}

main.go

package main

import (
	"context"

	log "github.com/sirupsen/logrus"
	"your-repo-path/config"
	"your-repo-path/internal/service"
	"your-repo-path/internal/utils"
	"your-repo-path/pkg/database"
	"your-repo-path/pkg/models"
	"your-repo-path/pkg/plug"
)

// plugConfig holds the orchestrator configuration
var coreConfig config.CoreConfig
var plugConfig config.PlugConfig
var databaseConfig models.DatabaseConfig

// init is used to load the orchestrator configuration
func init() {
	// Load the orchestrator configuration
	localCoreConfig, err := config.LoadConfig[config.CoreConfig](coreConfig)
	if err != nil {
		log.Panic(err)
	}
	coreConfig = localCoreConfig

	// Load the plug configuration
	localPlugConfig, err := config.LoadConfig[config.PlugConfig](plugConfig)
	if err != nil {
		log.Panic(err)
	}
	plugConfig = localPlugConfig

	// Load the database configuration
	localDatabaseConfig, err := config.LoadConfig[models.DatabaseConfig](databaseConfig)
	if err != nil {
		log.Panic(err)
	}
	databaseConfig = localDatabaseConfig
}

func main() {
	var err error
	var ctx = context.Background()
	// Initiate logging setup
	utils.SetupLogger(coreConfig.LogLevel, coreConfig.LogFormat)

	// Initiate database connection
	err = database.Connect(ctx, databaseConfig)
	if err != nil {
		log.Fatal(err)
	}

	// Setup Source
	source := models.Source{
		DisplayName: plugConfig.DisplayName,
		Domain:      models.SourceDomain(plugConfig.Domain),
		Icon:        plugConfig.Icon,
	}

	err = plug.SetupOpenTelemetry(ctx, "your-plug")
	if err != nil {
		log.Fatal(err)
	}

	plug.SetTaskExecutionFunction(service.plugInterface)
	plug.SetGetMessageExecutionFunction(service.YourMessageFunction)
	err = plug.Listen(ctx, ":8080", source)
	if err != nil {
		panic(err)
	}
}