sshpoke/internal/server/driver/util/params.go

28 lines
582 B
Go
Raw Normal View History

2023-11-17 20:39:00 +03:00
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 {
2023-11-17 20:39:00 +03:00
return err
}
if val, canValidate := target.(ValidationAvailable); canValidate {
return val.Validate()
}
return nil
}