21 lines
442 B
Go
21 lines
442 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 {
|
||
|
if err := mapstructure.Decode(params, target); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
if val, canValidate := target.(ValidationAvailable); canValidate {
|
||
|
return val.Validate()
|
||
|
}
|
||
|
return nil
|
||
|
}
|