mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
fix plugin settings unmarshal by changing to "name.key".
This commit is contained in:
parent
43467dcac1
commit
37b131c74c
@ -3,6 +3,7 @@ package types
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/demodesk/neko/pkg/utils"
|
"github.com/demodesk/neko/pkg/utils"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -74,8 +75,17 @@ func (p PluginSettings) Unmarshal(name string, def any) error {
|
|||||||
if p == nil {
|
if p == nil {
|
||||||
return fmt.Errorf("%w: %s", ErrPluginSettingsNotFound, name)
|
return fmt.Errorf("%w: %s", ErrPluginSettingsNotFound, name)
|
||||||
}
|
}
|
||||||
if _, ok := p[name]; !ok {
|
// loop through the plugin settings and take only the one that starts with the name
|
||||||
|
// because the settings are stored in a map["plugin_name.setting_name"] = value
|
||||||
|
newMap := make(map[string]any)
|
||||||
|
for k, v := range p {
|
||||||
|
if strings.HasPrefix(k, name+".") {
|
||||||
|
newMap[strings.TrimPrefix(k, name+".")] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Printf("newMap: %+v\n", newMap)
|
||||||
|
if len(newMap) == 0 {
|
||||||
return fmt.Errorf("%w: %s", ErrPluginSettingsNotFound, name)
|
return fmt.Errorf("%w: %s", ErrPluginSettingsNotFound, name)
|
||||||
}
|
}
|
||||||
return utils.Decode(p[name], def)
|
return utils.Decode(newMap, def)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user