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"`
|
CanSeeInactiveCursors bool `json:"can_see_inactive_cursors" mapstructure:"can_see_inactive_cursors"`
|
||||||
|
|
||||||
// plugin scope
|
// plugin scope
|
||||||
Plugins map[string]any `json:"plugins"`
|
Plugins PluginSettings `json:"plugins"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MemberProvider interface {
|
type MemberProvider interface {
|
||||||
|
@ -2,10 +2,16 @@ package types
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/demodesk/neko/pkg/utils"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrPluginSettingsNotFound = errors.New("plugin settings not found")
|
||||||
|
)
|
||||||
|
|
||||||
type Plugin interface {
|
type Plugin interface {
|
||||||
Name() string
|
Name() string
|
||||||
Config() PluginConfig
|
Config() PluginConfig
|
||||||
@ -61,3 +67,15 @@ func (p *PluginManagers) Validate() error {
|
|||||||
|
|
||||||
return nil
|
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"`
|
MercifulReconnect bool `json:"merciful_reconnect"`
|
||||||
|
|
||||||
// plugin scope
|
// plugin scope
|
||||||
Plugins map[string]any `json:"plugins"`
|
Plugins PluginSettings `json:"plugins"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Session interface {
|
type Session interface {
|
||||||
|
Loading…
Reference in New Issue
Block a user