compat

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2023 License: CC-BY-4.0, MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Messenger sends notifications.
	Messenger = Capability("messenger")
	// Configurer are consigurables.
	Configurer = Capability("configurer")
	// Storager stores data.
	Storager = Capability("storager")
	// Webhooker registers webhooks.
	Webhooker = Capability("webhooker")
	// Displayer displays instructions.
	Displayer = Capability("displayer")
)

Variables

This section is empty.

Functions

func HasSupport

func HasSupport(p PluginInstance, toCheck Capability) bool

HasSupport tests a PluginInstance for a capability.

Types

type Capabilities

type Capabilities []Capability

Capabilities is a slice of module.

func (Capabilities) Strings

func (m Capabilities) Strings() []string

Strings converts []Module to []string.

type Capability

type Capability string

Capability is a capability the plugin provides.

type Info

type Info struct {
	Version     string
	Author      string
	Name        string
	Website     string
	Description string
	License     string
	ModulePath  string
}

Info is the plugin info.

func (Info) String

func (c Info) String() string

type Message

type Message struct {
	Message  string
	Title    string
	Priority int
	Extras   map[string]interface{}
}

Message describes a message to be send by MessageHandler#SendMessage.

type MessageHandler

type MessageHandler interface {
	// SendMessage see plugin.MessageHandler
	SendMessage(msg Message) error
}

MessageHandler see plugin.MessageHandler.

type Plugin

type Plugin interface {
	PluginInfo() Info
	NewPluginInstance(ctx UserContext) PluginInstance
	APIVersion() string
}

Plugin is an abstraction of plugin handler.

func Wrap

func Wrap(p *plugin.Plugin) (Plugin, error)

Wrap wraps around a raw go plugin to provide typesafe access.

type PluginInstance

type PluginInstance interface {
	Enable() error
	Disable() error

	// GetDisplay see Displayer
	GetDisplay(location *url.URL) string

	// DefaultConfig see Configurer
	DefaultConfig() interface{}
	// ValidateAndSetConfig see Configurer
	ValidateAndSetConfig(c interface{}) error

	// SetMessageHandler see Messenger#SetMessageHandler
	SetMessageHandler(h MessageHandler)

	// RegisterWebhook see Webhooker#RegisterWebhook
	RegisterWebhook(basePath string, mux *gin.RouterGroup)

	// SetStorageHandler see Storager#SetStorageHandler.
	SetStorageHandler(handler StorageHandler)

	// Returns the supported modules, f.ex. storager
	Supports() Capabilities
}

PluginInstance is an encapsulation layer of plugin instances of different backends.

type PluginV1

type PluginV1 struct {
	Info        papiv1.Info
	Constructor func(ctx papiv1.UserContext) papiv1.Plugin
}

PluginV1 is an abstraction of a plugin written in the v1 plugin API. Exported for testing purposes only.

func (PluginV1) APIVersion

func (c PluginV1) APIVersion() string

APIVersion returns the API version.

func (PluginV1) NewPluginInstance

func (c PluginV1) NewPluginInstance(ctx UserContext) PluginInstance

NewPluginInstance implements compat/Plugin.

func (PluginV1) PluginInfo

func (c PluginV1) PluginInfo() Info

PluginInfo implements compat/Plugin.

type PluginV1Instance

type PluginV1Instance struct {
	// contains filtered or unexported fields
}

PluginV1Instance is an adapter for plugin using v1 API.

func (*PluginV1Instance) DefaultConfig

func (c *PluginV1Instance) DefaultConfig() interface{}

DefaultConfig see papiv1.Configurer.

func (*PluginV1Instance) Disable

func (c *PluginV1Instance) Disable() error

Disable implements wrapper.Plugin.

func (*PluginV1Instance) Enable

func (c *PluginV1Instance) Enable() error

Enable implements wrapper.Plugin.

func (*PluginV1Instance) GetDisplay

func (c *PluginV1Instance) GetDisplay(location *url.URL) string

GetDisplay see papiv1.Displayer.

func (*PluginV1Instance) RegisterWebhook

func (c *PluginV1Instance) RegisterWebhook(basePath string, mux *gin.RouterGroup)

RegisterWebhook see papiv1.Webhooker.

func (*PluginV1Instance) SetMessageHandler

func (c *PluginV1Instance) SetMessageHandler(h MessageHandler)

SetMessageHandler see papiv1.Messenger.

func (*PluginV1Instance) SetStorageHandler

func (c *PluginV1Instance) SetStorageHandler(handler StorageHandler)

SetStorageHandler see papiv1.Storager.

func (*PluginV1Instance) Supports

func (c *PluginV1Instance) Supports() Capabilities

Supports returns a slice of capabilities the plugin instance provides.

func (*PluginV1Instance) ValidateAndSetConfig

func (c *PluginV1Instance) ValidateAndSetConfig(config interface{}) error

ValidateAndSetConfig see papiv1.Configurer.

type PluginV1MessageHandler

type PluginV1MessageHandler struct {
	WrapperHandler MessageHandler
}

PluginV1MessageHandler is an adapter for messenger plugin handler using v1 API.

func (*PluginV1MessageHandler) SendMessage

func (c *PluginV1MessageHandler) SendMessage(msg papiv1.Message) error

SendMessage implements papiv1.MessageHandler.

type PluginV1StorageHandler

type PluginV1StorageHandler struct {
	WrapperHandler StorageHandler
}

PluginV1StorageHandler is a wrapper for v1 storage handler.

func (*PluginV1StorageHandler) Load

func (c *PluginV1StorageHandler) Load() ([]byte, error)

Load implements wrapper.Storager.

func (*PluginV1StorageHandler) Save

func (c *PluginV1StorageHandler) Save(b []byte) error

Save implements wrapper.Storager.

type StorageHandler

type StorageHandler interface {
	Save(b []byte) error
	Load() ([]byte, error)
}

StorageHandler see plugin.StorageHandler.

type UserContext

type UserContext struct {
	ID    uint
	Name  string
	Admin bool
}

UserContext is the user context used to create plugin instance.

Jump to

Keyboard shortcuts

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