add PluginSettings unmarshaller.

This commit is contained in:
Miroslav Šedivý 2024-06-16 16:42:32 +02:00
parent ae117ccdbb
commit 5a04066c55
3 changed files with 20 additions and 2 deletions

View File

@ -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 {

View File

@ -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)
}

View File

@ -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 {