api

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HookType

type HookType uint8
const (
	StartHook HookType = iota
	EndHook
	CreateCgroupHook
	DestroyCgroupHook
)

type Plugin

type Plugin interface {
	// Get the plugin name, should be consistent with the config file
	Name() string

	// Get the plugin version, could be used for simple version control
	Version() string

	// Load the plugin with the metadata, e.g., read the config file
	Load(meta PluginMeta) error

	// Unload the plugin, e.g., close the file descriptor
	Unload(meta PluginMeta) error

	/*
		Hook processing functions:
			@param ctx: The context of the plugin. Request and other data could
						be accessed from the context.
			            The output of the plugin should be stored in the context.
		See PluginContext for details.
	*/
	StartHook(ctx *PluginContext)
	EndHook(ctx *PluginContext)
	CreateCgroupHook(ctx *PluginContext)
	DestroyCgroupHook(ctx *PluginContext)
}

A plugin is a shared object that implements the Plugin interface

type PluginContext

type PluginContext struct {
	GrpcCtx context.Context
	Type    HookType
	Keys    map[string]any
	// contains filtered or unexported fields
}

func NewContext

func NewContext(ctx context.Context, req proto.Message, t HookType, hs *[]PluginHandler) *PluginContext

func (*PluginContext) Abort

func (c *PluginContext) Abort()

Plugin could call this to prevent the following plugins from being called.

func (*PluginContext) Get

func (c *PluginContext) Get(key string) any

func (*PluginContext) Next

func (c *PluginContext) Next()

Plugin could call this to hand over the control to the next plugin. When this returned, the caller may continue.

func (*PluginContext) Request

func (c *PluginContext) Request() proto.Message

func (*PluginContext) Set

func (c *PluginContext) Set(key string, value any)

func (*PluginContext) Start

func (c *PluginContext) Start()

This should only be called by the plugin daemon

type PluginHandler

type PluginHandler func(*PluginContext)

type PluginMeta

type PluginMeta struct {
	Name   string `yaml:"Name"`
	Path   string `yaml:"Path"`
	Config string `yaml:"Config"`
}

Jump to

Keyboard shortcuts

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