types

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIPlugin

type APIPlugin interface {
	Plugin
	// A router mounted on /. Generally, keep API extensions inside of
	// `/api/`; this interface gives / for well-known URIs, etc.
	Route(chi.Router)
}

A plugin with an API router.

type CrossPlugin

type CrossPlugin interface {
	Plugin
	// Called after all other plugins have been initialized.
	Extend(map[string]Plugin) error
}

A plugin that extends another plugin, or just has access to the plugin map.

type DB

type DB struct{ *bun.DB }

func (*DB) CheckAuthToken

func (db *DB) CheckAuthToken(token string) (models.User, error)

func (*DB) GetAuthToken

func (db *DB) GetAuthToken(token string) (models.AuthToken, error)

func (*DB) GetUser

func (db *DB) GetUser(id string) (models.User, error)

func (*DB) IssueAuthToken

func (db *DB) IssueAuthToken(u models.User) (token string, err error)

type DatabasePlugin

type DatabasePlugin interface {
	Plugin
	Migrations() map[uint]func(*DB) error
}

A plugin with managed file-based SQL migrations. Migrations() returns a map of Unix timestamps to Go migrations. Any migrations since the last are each executed until one throws an error. On error, Destroy() is called, the database is restored, and an error is logged.

type InternalHandle

type InternalHandle any

func HandleFrom

func HandleFrom(m any, p Plugin) InternalHandle

type Plugin

type Plugin interface {
	Init(*log.Logger, PluginParams) error
	// Returns the D-Bus or Java–style name for the plugin. Must not rely
	// on an earlier Init() call.
	Name() string
	// Function to close connections, end requests, etc.
	Destroy()
}

A plugin.

There is an example plugin in the package codeberg.org/libreedu/hub/plugins/example which simply registers the endpoint `/api/example-plugin` and returns the string "Hello, world!"

type PluginParams

type PluginParams struct {
	// A struct containing a bun DB, which should be Postgres. If you
	// prefer, you can access a `*sql.DB` at `params.DB.DB.DB`.
	DB *DB

	// A file handle for a config file. If there is no configuration file,
	// this is set to nil. This is owned by the manager - the file will be
	// closed after the AddPlugins function (when Init is called) ends.
	ConfigHandle io.ReadSeekCloser

	Unstable unstableAPI
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL