Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrorType = reflect.TypeOf((*error)(nil)).Elem()
)
exported shortcuts to make it easier to call ValidateFunction
Functions ¶
func CheckTypeCompatibility ¶
CheckTypeCompatibility checks whether `got` is a valid type for `want`, and returns a descriptive error otherwise.
Examples of positive compatibility:
want=int, got=int want=interface{}, got=string want=interface{}, got=nil want=error, got=untyped nil want=error, got=error-typed nil want=io.ReadWriter, got=io.Writer want=[]string, got=[]string want=struct{}, got=struct{}
Examples of negative compatibility:
want=error, got=string nil want=io.Reader, got=io.Writer want=[]struct{}, got []string want=*string, got=string want=*string, got=*int want=struct{}, got=*struct{} want=[]interface{}, got=[]string
func ValidateFunction ¶
ValidateFunction checks whether `f` is a function, and whether the input parameters and the return arguments have the correct number and types.
Example ¶
kv := struct{ Key string }{} // the signature of json.Unmarshal is // func Unmarshal(data []byte, v interface{}) error if err := ValidateFunction(json.Unmarshal, []reflect.Type{ErrorType}, []byte(`{"key": "value"}`), kv); err != nil { log.Fatal(err) }
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.