-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathvalidate.go
More file actions
31 lines (25 loc) · 550 Bytes
/
validate.go
File metadata and controls
31 lines (25 loc) · 550 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package goconfig
import (
"errors"
"reflect"
)
func validateConfigTarget(c interface{}) error {
if c == nil {
return errors.New("config target cannot be nil")
}
v := reflect.ValueOf(c)
if v.Kind() != reflect.Ptr {
return errors.New("config target must be a pointer")
}
if v.IsNil() {
return errors.New("config target cannot be nil")
}
v = reflect.Indirect(v)
if v.Kind() == reflect.Ptr {
v = reflect.Indirect(v)
}
if v.Kind() != reflect.Struct {
return errors.New("config target must point to a struct")
}
return nil
}