28 lines
582 B
Go
28 lines
582 B
Go
package util
|
|
|
|
import (
|
|
"github.com/Neur0toxine/sshpoke/internal/config"
|
|
"github.com/mitchellh/mapstructure"
|
|
)
|
|
|
|
type ValidationAvailable interface {
|
|
Validate() error
|
|
}
|
|
|
|
func UnmarshalParams(params config.DriverParams, target ValidationAvailable) error {
|
|
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
|
|
Result: target,
|
|
WeaklyTypedInput: true,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := dec.Decode(params); err != nil {
|
|
return err
|
|
}
|
|
if val, canValidate := target.(ValidationAvailable); canValidate {
|
|
return val.Validate()
|
|
}
|
|
return nil
|
|
}
|