hub

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: AGPL-3.0 Imports: 17 Imported by: 0

README

hub

Issues

A plugin-based application framework, for one app or many! Use this as a Nextcloud-like platform, or just to bootstrap your (AGPLv3) app.

Documentation

Overview

Currently this package only contains the definitions for various plugin types. It is planned to contain a plugin manager interface and an implementation of one to make simple "startup scripts" listing plugins.

Index

Constants

This section is empty.

Variables

View Source
var Version string

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 added in v0.0.2

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 Manager

type Manager interface {
	// On error, returns the index of the plugin erroring and the error
	// received, or “(-1, nil)“ if all plugins initialized successfully.
	AddPlugins(...Plugin) (int, error)
	AddPluginFile(filename string) error
	GetPluginMap() map[string]Plugin
	// Finishishes initializing each plugin, specifically by passing the
	// plugin map to CrossPlugins.
	Finalize()
	// Starts listening. If the Server pointer is nil, Listen will use the
	// implementation default. Implementors should not modify a passed
	// Server except its Handler.
	Listen(*http.Server)
	// Shuts down the “http.Server“ in Listen() and calls Destroy() on
	// each plugin. Returns any error in shutting down, for instance from
	// “http.Server.Shutdown()“.
	Shutdown() error
}

func GetDefaultManager

func GetDefaultManager(logger *log.Logger) (Manager, error)

Returns a Manager using “config/hub.yml“ to set up.

func GetManager

func GetManager(logger *log.Logger, dsn string) (Manager, error)

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.
	DBusName() 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!"

Plugins should use package-scope variables, if they must work with `-buildmode plugin`, because exported shared object types cannot maintain state.

type PluginParams

type PluginParams struct {
	// A struct containing a bun DB, generally Postgres or another system
	// supporting  PL/pgSQL. If you prefer, you can access a `*sql.DB` at
	// `plugin.DB.DB.DB`.
	//
	// Please be mindful of other plugins and contain your plugin's data
	// in its own Postgres schema.
	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
}

Directories

Path Synopsis
cmd
internal
db
This package contains useful middleware functions.
This package contains useful middleware functions.
The `models` module provides core database types like User.
The `models` module provides core database types like User.
plugins
auth_oidc
Use codeberg.org/libreedu/hub/plugins/auth_oidc/import in launch script
Use codeberg.org/libreedu/hub/plugins/auth_oidc/import in launch script
auth_oidc/import
(Incomplete) Plugin auth_oidc adds support for OpenID Connect Discovery and authentication.
(Incomplete) Plugin auth_oidc adds support for OpenID Connect Discovery and authentication.
auth_userpass
Use codeberg.org/libreedu/hub/plugins/auth_userpass/import in launch script
Use codeberg.org/libreedu/hub/plugins/auth_userpass/import in launch script
auth_userpass/import
This plugin adds support for logging in with username, password, and extensible other factors.
This plugin adds support for logging in with username, password, and extensible other factors.
avatar
Use codeberg.org/libreedu/hub/plugins/avatar/import in launch script
Use codeberg.org/libreedu/hub/plugins/avatar/import in launch script
avatar/import
This plugin allows viewing and uploading user avatars.
This plugin allows viewing and uploading user avatars.
core
Use codeberg.org/libreedu/hub/plugins/core/import in launch script
Use codeberg.org/libreedu/hub/plugins/core/import in launch script
example
Use codeberg.org/libreedu/hub/plugins/example/import in launch script
Use codeberg.org/libreedu/hub/plugins/example/import in launch script

Jump to

Keyboard shortcuts

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