registry

package
v0.0.0-...-5722567 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: Apache-2.0 Imports: 5 Imported by: 3

Documentation

Overview

Package registry provides a central way to register and use all available saving backends and plugins. All options should be registered prior to the program starting, normally through init().

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComparePasswords

func ComparePasswords(method, password, truth string) (bool, error)

ComparePasswords compares a password to a 'truth'. The bool represents whether comparison is successful. Error is returned if there is any error during computation. You can savely use it in parallel.

func PasswordMethodExists

func PasswordMethodExists(method string) bool

RegisterPasswordMethod returns whether the password method is known. You can savely use it in parallel.

func RegisterDataSafe

func RegisterDataSafe(t DataSafe, name string) error

RegisterDataSafe registeres a data safe. The name of the data safe is used as an identifier and must be unique. You can savely use it in parallel.

func RegisterPasswordMethod

func RegisterPasswordMethod(method PasswordMethod, name string) error

RegisterPasswordMethod registeres a password method. The name of the password method is used as an identifier and must be unique. You can savely use it in parallel.

func RegisterPlugin

func RegisterPlugin(f PluginFactory, name string) error

RegisterPlugin registeres a plugin. The name of the plugin is used as an identifier and must be unique. You can savely use it in parallel.

Types

type AlreadyRegisteredError

type AlreadyRegisteredError string

AlreadyRegisteredError represents an error where an option is already registeres

func (AlreadyRegisteredError) Error

func (a AlreadyRegisteredError) Error() string

Error returns the error description

type Announcement

type Announcement struct {
	Header, Message string
	Time            time.Time
}

Announcement represents a single announcement. It has two main parts: a short header (something like a short summary) and the actual message. Time contains the publication time of the announcement.

type DataSafe

type DataSafe interface {
	InitialiseDatasafe(config []byte) error
	GetConfig(key, plugin string) ([]byte, error)
	SetConfig(key, plugin string, config []byte) error
	SaveAnnouncement(key string, a Announcement) (id string, err error)
	GetAnnouncement(key, id string) (Announcement, error)
	GetAllAnnouncements(key string) ([]Announcement, error)
	GetAnnouncementKeys(key string) ([]string, error)
}

DataSafe represents a backend for save storage of questionnaire results. The keys of the announcement should be kept in the order they arrive.

var CurrentDataSafe DataSafe = nil

CurrentDataSafe holds the current data safe. It must be saved before loading any Plugin and never be changed after that.

func GetDataSafe

func GetDataSafe(name string) (DataSafe, bool)

GetDataSafe returns a data safe. The bool indicates whether it existed. You can only use it if the bool is true.

type PasswordMethod

type PasswordMethod func(password, truth string) (bool, error)

PasswordMethod enables to compare the password against different 'truth'. The truth might be plain text, a password hash or similar. Truth must contain every information needed to compare the password. The function must be callable in parallel at the same time. The bool represents whether comparison is successful. Error is returned if there is any error during computation.

type Plugin

type Plugin interface {
	GetConfig() template.HTML
	ProcessConfigChange(r *http.Request) error
	NewAnnouncement(a Announcement, id string)
}

Plugin represents an announcement plugin. All methods must be save to use in parallel.

type PluginFactory

type PluginFactory func(key, shortDescription string, errorChannel chan string) (Plugin, error)

PluginFactory represents a function to generate a new Plugin. The Plugin loads its configuration from the DataSafe.

func GetPlugin

func GetPlugin(name string) (PluginFactory, bool)

GetPlugin returns a plugin factory. The bool indicates whether it existed. You can only use it if the bool is true.

Jump to

Keyboard shortcuts

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