mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add PluginSettings unmarshaller.
This commit is contained in:
parent
ae117ccdbb
commit
5a04066c55
@ -23,7 +23,7 @@ type MemberProfile struct {
|
||||
CanSeeInactiveCursors bool `json:"can_see_inactive_cursors" mapstructure:"can_see_inactive_cursors"`
|
||||
|
||||
// plugin scope
|
||||
Plugins map[string]any `json:"plugins"`
|
||||
Plugins PluginSettings `json:"plugins"`
|
||||
}
|
||||
|
||||
type MemberProvider interface {
|
||||
|
@ -2,10 +2,16 @@ package types
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/demodesk/neko/pkg/utils"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrPluginSettingsNotFound = errors.New("plugin settings not found")
|
||||
)
|
||||
|
||||
type Plugin interface {
|
||||
Name() string
|
||||
Config() PluginConfig
|
||||
@ -61,3 +67,15 @@ func (p *PluginManagers) Validate() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type PluginSettings map[string]any
|
||||
|
||||
func (p PluginSettings) Unmarshal(name string, def any) error {
|
||||
if p == nil {
|
||||
return fmt.Errorf("%w: %s", ErrPluginSettingsNotFound, name)
|
||||
}
|
||||
if _, ok := p[name]; !ok {
|
||||
return fmt.Errorf("%w: %s", ErrPluginSettingsNotFound, name)
|
||||
}
|
||||
return utils.Decode(p[name], def)
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ type Settings struct {
|
||||
MercifulReconnect bool `json:"merciful_reconnect"`
|
||||
|
||||
// plugin scope
|
||||
Plugins map[string]any `json:"plugins"`
|
||||
Plugins PluginSettings `json:"plugins"`
|
||||
}
|
||||
|
||||
type Session interface {
|
||||
|
Loading…
Reference in New Issue
Block a user