// Create an Action that invokes the supplied function, returning whatever it
// returns. The signature of the function must match that of the mocked method
// exactly.
779925
func Invoke(f interface{}) Action {
	// Make sure f is a function.
	fv := reflect.ValueOf(f)
	fk := fv.Kind()

	if fk != reflect.Func {
		desc := "<nil>"
		if fk != reflect.Invalid {
			desc = fv.Type().String()
		}

		panic(fmt.Sprintf("Invoke: expected function, got %s", desc))
	}

	return &invokeAction{fv}
}
390854
func (mr *MethodRepository) InvokeMethod(c context.Context, r *Request) *Response {
	var h Handler
	res := NewResponse(r)
	h, res.Error = mr.TakeMethod(r)
	if res.Error != nil {
		return res
	}
	res.Result, res.Error = h.ServeJSONRPC(WithRequestID(c, r.ID), r.Params)
	if res.Error != nil {
		res.Result = nil
	}
	return res
}
930805
func (client *Client) Invoke(action string, args interface{}, response interface{}) error {
	if err := client.ensureProperties(); err != nil {
		return err
	}

	//init endpoint
	if err := client.initEndpoint(); err != nil {
		return err
	}

	request := Request{}
	request.init(client.version, action, client.AccessKeyId, client.securityToken, client.regionID)

	query := util.ConvertToQueryValues(request)
	util.SetQueryValues(args, &query)

	// Sign request
	signature := util.CreateSignatureForRequest(ECSRequestMethod, &query, client.AccessKeySecret)

	// Generate the request URL
	requestURL := client.endpoint + "?" + query.Encode() + "&Signature=" + url.QueryEscape(signature)

	httpReq, err := http.NewRequest(ECSRequestMethod, requestURL, nil)

	if err != nil {
		return GetClientError(err)
	}

	// TODO move to util and add build val flag
	httpReq.Header.Set("X-SDK-Client", `AliyunGO/`+Version+client.businessInfo)

	httpReq.Header.Set("User-Agent", httpReq.UserAgent()+" "+client.userAgent)

	t0 := time.Now()
	httpResp, err := client.httpClient.Do(httpReq)
	t1 := time.Now()
	if err != nil {
		return GetClientError(err)
	}
	statusCode := httpResp.StatusCode

	if client.debug {
		log.Printf("Invoke %s %s %d (%v)", ECSRequestMethod, requestURL, statusCode, t1.Sub(t0))
	}

	defer httpResp.Body.Close()
	body, err := ioutil.ReadAll(httpResp.Body)

	if err != nil {
		return GetClientError(err)
	}

	if client.debug {
		var prettyJSON bytes.Buffer
		err = json.Indent(&prettyJSON, body, "", "    ")
		log.Println(string(prettyJSON.Bytes()))
	}

	if statusCode >= 400 && statusCode <= 599 {
		errorResponse := ErrorResponse{}
		err = json.Unmarshal(body, &errorResponse)
		ecsError := &Error{
			ErrorResponse: errorResponse,
			StatusCode:    statusCode,
		}
		return ecsError
	}

	err = json.Unmarshal(body, response)
	//log.Printf("%++v", response)
	if err != nil {
		return GetClientError(err)
	}

	return nil
}
600565
func NewFunctionDelayer(duration time.Duration) *FunctionDelayer {
	f := new(FunctionDelayer)
	f.Duration = duration
	f.timers = make(map[string]*time.Timer)
	return f
}
1018904
func (m *MockLambdaAPI) Invoke(arg0 *lambda.InvokeInput) (*lambda.InvokeOutput, error) {
	ret := m.ctrl.Call(m, "Invoke", arg0)
	ret0, _ := ret[0].(*lambda.InvokeOutput)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
1142464
func (c *Call) DoAndReturn(f interface{}) *Call {
	// TODO: Check arity and types here, rather than dying badly elsewhere.
	v := reflect.ValueOf(f)

	c.addAction(func(args []interface{}) []interface{} {
		vargs := make([]reflect.Value, len(args))
		ft := v.Type()
		for i := 0; i < len(args); i++ {
			if args[i] != nil {
				vargs[i] = reflect.ValueOf(args[i])
			} else {
				// Use the zero value for the arg.
				vargs[i] = reflect.Zero(ft.In(i))
			}
		}
		vrets := v.Call(vargs)
		rets := make([]interface{}, len(vrets))
		for i, ret := range vrets {
			rets[i] = ret.Interface()
		}
		return rets
	})
	return c
}
441656
func invokeShouldCreate(a, e, changes Task) (bool, error) {
	rv, err := reflectutils.InvokeMethod(e, "ShouldCreate", a, e, changes)
	if err != nil {
		if reflectutils.IsMethodNotFound(err) {
			return true, nil
		}
		return false, err
	}
	shouldCreate := rv[0].Interface().(bool)
	if !rv[1].IsNil() {
		err = rv[1].Interface().(error)
	}
	return shouldCreate, err
}
47824
func (mr *MockStatefulSetInterfaceMockRecorder) Create(arg0 interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockStatefulSetInterface)(nil).Create), arg0)
}
412405
func (b *bridge) createEvent(action string) *Event {
	event := createEvent(action)
	event.Source = b.source
	event.Actor = b.actor
	event.Request = b.request

	return event
}
831999
func (cc *EndorsementCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
	funcName, _ := stub.GetFunctionAndParameters()
	if function, ok := functions[funcName]; ok {
		return function(stub)
	}
	return shim.Error(fmt.Sprintf("Unknown function %s", funcName))
}
192990
func (v *IDispatch) CallMethod(name string, params ...interface{}) (*VARIANT, error) {
	return v.InvokeWithOptionalArgs(name, DISPATCH_METHOD, params)
}
1144389
func (ar *ActionRepository) RegisterKeyspaceAction(name string, method actionKeyspaceMethod) {
	ar.keyspaceActions[name] = method
}
157724
func (c ActionCollection) FirstCardCreateAction() *Action {
	sort.Sort(c)
	for _, action := range c {
		if action.DidCreateCard() {
			return action
		}
	}
	return nil
}
128620
func (f *MockFunction) ReturnToArgument(n int, v interface{}) *MockFunction {
	f.ReturnToArguments = append(f.ReturnToArguments, MockReturnToArgument{n, v})
	return f
}
950512
func Return() HandlerFunc {
	return func(ctx *Context) {
		var rt int
		action := ctx.Action()
		if action != nil {
			if i, ok := action.(ResponseTyper); ok {
				rt = i.ResponseType()
			}
		}

		ctx.Next()

		// if no route match or has been write, then return
		if action == nil || ctx.Written() {
			return
		}

		// if there is no return value or return nil
		if isNil(ctx.Result) {
			// then we return blank page
			ctx.Result = ""
		}

		var result = ctx.Result
		var statusCode = 0
		if res, ok := ctx.Result.(*StatusResult); ok {
			statusCode = res.Code
			result = res.Result
		}

		if rt == jsonResponse {
			encoder := json.NewEncoder(ctx)
			if len(ctx.Header().Get("Content-Type")) <= 0 {
				ctx.Header().Set("Content-Type", "application/json; charset=UTF-8")
			}

			switch res := result.(type) {
			case AbortError:
				if statusCode == 0 {
					statusCode = res.Code()
				}
				ctx.WriteHeader(statusCode)
				encoder.Encode(map[string]string{
					"err": res.Error(),
				})
			case ErrorWithCode:
				if statusCode == 0 {
					statusCode = http.StatusOK
				}
				ctx.WriteHeader(statusCode)
				encoder.Encode(map[string]interface{}{
					"err":      res.Error(),
					"err_code": res.ErrorCode(),
				})
			case error:
				if statusCode == 0 {
					statusCode = http.StatusOK
				}
				ctx.WriteHeader(statusCode)
				encoder.Encode(map[string]string{
					"err": res.Error(),
				})
			case string:
				if statusCode == 0 {
					statusCode = http.StatusOK
				}
				ctx.WriteHeader(statusCode)
				encoder.Encode(map[string]string{
					"content": res,
				})
			case []byte:
				if statusCode == 0 {
					statusCode = http.StatusOK
				}
				ctx.WriteHeader(statusCode)
				encoder.Encode(map[string]string{
					"content": string(res),
				})
			default:
				if statusCode == 0 {
					statusCode = http.StatusOK
				}
				ctx.WriteHeader(statusCode)
				err := encoder.Encode(result)
				if err != nil {
					ctx.Result = err
					encoder.Encode(map[string]string{
						"err": err.Error(),
					})
				}
			}

			return
		} else if rt == xmlResponse {
			encoder := xml.NewEncoder(ctx)
			if len(ctx.Header().Get("Content-Type")) <= 0 {
				ctx.Header().Set("Content-Type", "application/xml; charset=UTF-8")
			}
			switch res := result.(type) {
			case AbortError:
				if statusCode == 0 {
					statusCode = res.Code()
				}
				ctx.WriteHeader(statusCode)
				encoder.Encode(XMLError{
					Content: res.Error(),
				})
			case error:
				if statusCode == 0 {
					statusCode = http.StatusOK
				}
				ctx.WriteHeader(statusCode)
				encoder.Encode(XMLError{
					Content: res.Error(),
				})
			case string:
				if statusCode == 0 {
					statusCode = http.StatusOK
				}
				ctx.WriteHeader(statusCode)
				encoder.Encode(XMLString{
					Content: res,
				})
			case []byte:
				if statusCode == 0 {
					statusCode = http.StatusOK
				}
				ctx.WriteHeader(statusCode)
				encoder.Encode(XMLString{
					Content: string(res),
				})
			default:
				if statusCode == 0 {
					statusCode = http.StatusOK
				}
				ctx.WriteHeader(statusCode)
				err := encoder.Encode(result)
				if err != nil {
					ctx.Result = err
					encoder.Encode(XMLError{
						Content: err.Error(),
					})
				}
			}
			return
		}

		switch res := result.(type) {
		case AbortError, error:
			ctx.HandleError()
		case []byte:
			if statusCode == 0 {
				statusCode = http.StatusOK
			}
			ctx.WriteHeader(statusCode)
			ctx.Write(res)
		case string:
			if statusCode == 0 {
				statusCode = http.StatusOK
			}
			ctx.WriteHeader(statusCode)
			ctx.WriteString(res)
		}
	}
}
72620
func (mm *methodManager) AddFunction(
	name string, function interface{}, option ...Options) {
	if name == "" {
		panic("name can't be empty")
	}
	if function == nil {
		panic("function can't be nil")
	}
	f, ok := function.(reflect.Value)
	if !ok {
		f = reflect.ValueOf(function)
	}
	if f.Kind() != reflect.Func {
		panic("function must be func or bound method")
	}
	var options Options
	if len(option) > 0 {
		options = option[0]
	}
	if options.NameSpace != "" && name != "*" {
		name = options.NameSpace + "_" + name
	}
	mm.mmLocker.Lock()
	if mm.RemoteMethods[strings.ToLower(name)] == nil {
		mm.MethodNames = append(mm.MethodNames, name)
	}
	mm.RemoteMethods[strings.ToLower(name)] = &Method{f, options}
	mm.mmLocker.Unlock()
}
1303225
func GenerateGFunction(rm rbac.RoleManager) func(args ...interface{}) (interface{}, error) {
	return func(args ...interface{}) (interface{}, error) {
		name1 := args[0].(string)
		name2 := args[1].(string)

		if rm == nil {
			return name1 == name2, nil
		} else if len(args) == 2 {
			res, _ := rm.HasLink(name1, name2)
			return res, nil
		} else {
			domain := args[2].(string)
			res, _ := rm.HasLink(name1, name2, domain)
			return res, nil
		}
	}
}