...

Source file src/github.com/aws/smithy-go/encoding/httpbinding/shared_test.go

Documentation: github.com/aws/smithy-go/encoding/httpbinding

     1  package httpbinding
     2  
     3  import (
     4  	"fmt"
     5  	"reflect"
     6  )
     7  
     8  func reflectCall(funcValue reflect.Value, args []interface{}) error {
     9  	argValues := make([]reflect.Value, len(args))
    10  
    11  	for i, v := range args {
    12  		value := reflect.ValueOf(v)
    13  		argValues[i] = value
    14  	}
    15  
    16  	retValues := funcValue.Call(argValues)
    17  	if len(retValues) > 0 {
    18  		errValue := retValues[0]
    19  
    20  		if typeName := errValue.Type().Name(); typeName != "error" {
    21  			panic(fmt.Sprintf("expected first return argument to be error but got %v", typeName))
    22  		}
    23  
    24  		if errValue.IsNil() {
    25  			return nil
    26  		}
    27  
    28  		if err, ok := errValue.Interface().(error); ok {
    29  			return err
    30  		}
    31  
    32  		panic(fmt.Sprintf("expected %v to return error type, but got %v", funcValue.Type().String(), retValues[0].Type().String()))
    33  	}
    34  
    35  	return nil
    36  }
    37  

View as plain text