neko/pkg/types/plugins.go

57 lines
957 B
Go
Raw Normal View History

2022-04-16 07:28:00 +12:00
package types
import (
2022-04-19 22:14:59 +12:00
"errors"
2022-04-16 07:28:00 +12:00
"github.com/spf13/cobra"
)
type Plugin interface {
2022-04-19 22:14:59 +12:00
Name() string
2022-04-16 07:28:00 +12:00
Config() PluginConfig
2022-04-20 21:31:37 +12:00
Start(PluginManagers) error
2022-04-16 07:28:00 +12:00
Shutdown() error
}
2022-05-03 23:17:04 +12:00
type DependablePlugin interface {
Plugin
DependsOn() []string
}
2022-04-19 22:14:59 +12:00
type ExposablePlugin interface {
Plugin
ExposeService() any
}
2022-04-16 07:28:00 +12:00
type PluginConfig interface {
Init(cmd *cobra.Command) error
Set()
}
type PluginManagers struct {
2022-04-19 22:14:59 +12:00
SessionManager SessionManager
WebSocketManager WebSocketManager
ApiManager ApiManager
LoadServiceFromPlugin func(string) (any, error)
}
func (p *PluginManagers) Validate() error {
if p.SessionManager == nil {
return errors.New("SessionManager is nil")
}
if p.WebSocketManager == nil {
return errors.New("WebSocketManager is nil")
}
if p.ApiManager == nil {
return errors.New("ApiManager is nil")
}
if p.LoadServiceFromPlugin == nil {
return errors.New("LoadServiceFromPlugin is nil")
}
return nil
2022-04-16 07:28:00 +12:00
}