chore: refactor plugin structure (#18335)
This commit is contained in:
parent
9127e1a913
commit
07fa1b64f8
127 changed files with 861 additions and 938 deletions
45
plugin/error.go
Normal file
45
plugin/error.go
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/evcc-io/evcc/util"
|
||||
)
|
||||
|
||||
type errorPlugin struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func init() {
|
||||
registry.Add("error", NewErrorFromConfig)
|
||||
}
|
||||
|
||||
// NewErrorFromConfig creates error provider
|
||||
func NewErrorFromConfig(other map[string]interface{}) (Plugin, error) {
|
||||
var cc struct {
|
||||
Error string
|
||||
}
|
||||
|
||||
if err := util.DecodeOther(other, &cc); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err := knownErrors([]byte(cc.Error))
|
||||
if err == nil {
|
||||
return nil, fmt.Errorf("unknown error: %s", cc.Error)
|
||||
}
|
||||
|
||||
o := &errorPlugin{
|
||||
err: err,
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
var _ IntSetter = (*errorPlugin)(nil)
|
||||
|
||||
func (o *errorPlugin) IntSetter(param string) (func(int64) error, error) {
|
||||
return func(int64) error {
|
||||
return o.err
|
||||
}, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue