當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Type.NumIn方法代碼示例

本文整理匯總了Golang中reflect.Type.NumIn方法的典型用法代碼示例。如果您正苦於以下問題:Golang Type.NumIn方法的具體用法?Golang Type.NumIn怎麽用?Golang Type.NumIn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在reflect.Type的用法示例。


在下文中一共展示了Type.NumIn方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getMethod

func getMethod(methodType reflect.Type, fn reflect.Value) *methodWrapper {
	if methodType.NumOut() != 1 {
		return nil
	}
	if methodType.Out(0) != typeOfError {
		return nil
	}
	if methodType.NumIn() == 2 {
		// Method needs two ins: receiver, *Conn.
		if methodType.In(1) != typeOfConn {
			return nil
		}
		return &methodWrapper{plain: true, fn: fn}
	}
	if methodType.NumIn() == 4 {
		// Method needs four ins: receiver, *Conn, request, *reply.
		if methodType.In(1) != typeOfConn {
			return nil
		}
		if methodType.In(3).Kind() != reflect.Ptr {
			return nil
		}
		return &methodWrapper{
			plain:        false,
			fn:           fn,
			requestType:  methodType.In(2),
			responseType: methodType.In(3).Elem()}
	}
	return nil
}
開發者ID:keep94,項目名稱:Dominator,代碼行數:30,代碼來源:server.go

示例2: makeClosure

func makeClosure(fv reflect.Value, ft reflect.Type) *function {
	fn := &function{
		call: fv,
	}

	var rt = Void
	var at []Type

	if n := ft.NumOut(); n != 0 {
		rt = makeRetType(reflect.New(ft.Out(0)))
	}

	if n := ft.NumIn(); n != 0 {
		at = make([]Type, n)

		for i := 0; i != n; i++ {
			at[i] = makeArgType(reflect.Zero(ft.In(i)))
		}
	}

	fn.Interface = Prepare(rt, at...)

	if err := constructClosure(fn); err != nil {
		panic(err)
	}

	runtime.SetFinalizer(fn, destroyClosure)
	return fn
}
開發者ID:achille-roussel,項目名稱:go-ffi,代碼行數:29,代碼來源:ffi.go

示例3: addImportsForType

// Add all necessary imports for the type, recursing as appropriate.
func addImportsForType(imports importMap, t reflect.Type) {
	// Add any import needed for the type itself.
	addImportForType(imports, t)

	// Handle special cases where recursion is needed.
	switch t.Kind() {
	case reflect.Array, reflect.Chan, reflect.Ptr, reflect.Slice:
		addImportsForType(imports, t.Elem())

	case reflect.Func:
		// Input parameters.
		for i := 0; i < t.NumIn(); i++ {
			addImportsForType(imports, t.In(i))
		}

		// Return values.
		for i := 0; i < t.NumOut(); i++ {
			addImportsForType(imports, t.Out(i))
		}

	case reflect.Map:
		addImportsForType(imports, t.Key())
		addImportsForType(imports, t.Elem())
	}
}
開發者ID:BanzaiMan,項目名稱:gcsfuse,代碼行數:26,代碼來源:generate.go

示例4: sigMatches

// Note: Methods take the receiver as the first argument, which the want
// signature doesn't include.
func sigMatches(got, want reflect.Type) bool {

	nin := want.NumIn()
	if got.NumIn()-1 != nin {
		return false
	}

	nout := want.NumOut()
	if got.NumOut() != nout {
		return false
	}

	for i := 0; i < nin; i++ {
		if got.In(i+1) != want.In(i) {
			return false
		}
	}

	for i := 0; i < nout; i++ {
		if got.Out(i) != want.Out(i) {
			return false
		}
	}
	return true
}
開發者ID:qinglong1983,項目名稱:py,代碼行數:27,代碼來源:goregister.go

示例5: verifyDeepCopyFunctionSignature

// Verifies whether a deep-copy function has a correct signature.
func verifyDeepCopyFunctionSignature(ft reflect.Type) error {
	if ft.Kind() != reflect.Func {
		return fmt.Errorf("expected func, got: %v", ft)
	}
	if ft.NumIn() != 3 {
		return fmt.Errorf("expected three 'in' params, got $v", ft)
	}
	if ft.NumOut() != 1 {
		return fmt.Errorf("expected one 'out' param, got %v", ft)
	}
	if ft.In(1).Kind() != reflect.Ptr {
		return fmt.Errorf("expected pointer arg for 'in' param 1, got: %v", ft)
	}
	if ft.In(1).Elem() != ft.In(0) {
		return fmt.Errorf("expected 'in' param 0 the same as param 1, got: %v", ft)
	}
	var forClonerType Cloner
	if expected := reflect.TypeOf(&forClonerType); ft.In(2) != expected {
		return fmt.Errorf("expected '%v' arg for 'in' param 2, got: '%v'", expected, ft.In(2))
	}
	var forErrorType error
	// This convolution is necessary, otherwise TypeOf picks up on the fact
	// that forErrorType is nil
	errorType := reflect.TypeOf(&forErrorType).Elem()
	if ft.Out(0) != errorType {
		return fmt.Errorf("expected error return, got: %v", ft)
	}
	return nil
}
開發者ID:qingyuancloud,項目名稱:qingyuan,代碼行數:30,代碼來源:cloner.go

示例6: FormatFuncArguments

func FormatFuncArguments(t reflect.Type) (decl string) {
	decl = "("
	in := make([]string, t.NumIn())

	for i := range in {
		in[i] = ValType(t.In(i))
	}

	decl += strings.Join(in, ",") + ")"

	out := make([]string, t.NumOut())
	if len(out) > 0 {

		for i := range out {
			out[i] = ValType(t.Out(i))
		}

		s := strings.Join(out, ",")

		if len(out) != 1 {
			s = "(" + s + ")"
		}

		decl += " " + s
	}
	return
}
開發者ID:TShadwell,項目名稱:fweight,代碼行數:27,代碼來源:goval.go

示例7: IsEqual

func (p *MethodMetadata) IsEqual(t reflect.Type) bool {
	if t.ConvertibleTo(p.Method.Type) {
		return false
	}

	baseIndex := 0
	if p.Method.Index >= 0 {
		baseIndex = 1
	}

	if t.NumIn()+baseIndex != p.Method.Type.NumIn() {
		return false
	}

	for i := 0; i < p.Method.Type.NumIn()-baseIndex; i++ {
		if p.Method.Type.In(baseIndex+i) != t.In(i) {
			return false
		}
	}

	for i := 0; i < p.Method.Type.NumOut(); i++ {
		if p.Method.Type.Out(baseIndex+i) != t.Out(i) {
			return false
		}
	}

	return true
}
開發者ID:gogap,項目名稱:aop,代碼行數:28,代碼來源:method_metadata.go

示例8: Prepare

func (ms *GobMarshaller) Prepare(name string, fn interface{}) (err error) {
	var (
		fT reflect.Type
	)
	// Gob needs to register type before encode/decode
	if fT = reflect.TypeOf(fn); fT.Kind() != reflect.Func {
		err = fmt.Errorf("fn is not a function but %v", fn)
		return
	}

	reg := func(v reflect.Value) (err error) {
		if !v.CanInterface() {
			err = fmt.Errorf("Can't convert to value in input of %v for name:%v", fn, name)
			return
		}

		gob.Register(v.Interface())
		return
	}

	for i := 0; i < fT.NumIn(); i++ {
		// create a zero value of the type of parameters
		if err = reg(reflect.Zero(fT.In(i))); err != nil {
			return
		}
	}

	for i := 0; i < fT.NumOut(); i++ {
		if err = reg(reflect.Zero(fT.Out(i))); err != nil {
			return
		}
	}

	return
}
開發者ID:MogeiWang,項目名稱:dingo,代碼行數:35,代碼來源:marshaller_gob.go

示例9: typeString_FuncOrMethod

func typeString_FuncOrMethod(
	name string,
	t reflect.Type,
	pkgPath string) (s string) {
	// Deal with input types.
	var in []string
	for i := 0; i < t.NumIn(); i++ {
		in = append(in, typeString(t.In(i), pkgPath))
	}

	// And output types.
	var out []string
	for i := 0; i < t.NumOut(); i++ {
		out = append(out, typeString(t.Out(i), pkgPath))
	}

	// Put it all together.
	s = fmt.Sprintf(
		"%s(%s) (%s)",
		name,
		strings.Join(in, ", "),
		strings.Join(out, ", "))

	return
}
開發者ID:chenqi123,項目名稱:cq_tkbl_api,代碼行數:25,代碼來源:type_string.go

示例10: newTypeFromFactoryFunction

func newTypeFromFactoryFunction(function interface{}, factoryType reflect.Type, parameters []interface{}) TypeFactory {
	if factoryType.NumOut() != 1 {
		return newInvalidType(fmt.Errorf("invalid number of return parameters: %d", factoryType.NumOut()))
	}

	kindOfGeneratedType := factoryType.Out(0).Kind()
	if kindOfGeneratedType != reflect.Interface && kindOfGeneratedType != reflect.Ptr {
		return newInvalidType(fmt.Errorf("return parameter is no interface or pointer but a %v", kindOfGeneratedType))
	}

	if factoryType.IsVariadic() {
		if factoryType.NumIn() > len(parameters) {
			return newInvalidType(fmt.Errorf("invalid number of input parameters for variadic function: got %d but expected at least %d", len(parameters), factoryType.NumIn()))
		}
	} else {
		if factoryType.NumIn() != len(parameters) {
			return newInvalidType(fmt.Errorf("invalid number of input parameters: got %d but expected %d", len(parameters), factoryType.NumIn()))
		}
	}

	t := &typeFactory{
		factory:     reflect.ValueOf(function),
		factoryType: factoryType,
	}

	var err error
	t.factoryArguments, err = buildFactoryCallArguments(factoryType, parameters)
	if err != nil {
		return newInvalidType(err)
	}

	return t
}
開發者ID:optimuse,項目名稱:goldi,代碼行數:33,代碼來源:type.go

示例11: InTypes

func InTypes(fnType reflect.Type) []reflect.Type {
	var types []reflect.Type
	for i := 0; i < fnType.NumIn(); i++ {
		types = append(types, fnType.In(i))
	}
	return types
}
開發者ID:gemrs,項目名稱:gem,代碼行數:7,代碼來源:conversions.go

示例12: checkFunc

func checkFunc(fnType reflect.Type) (bool, error) {
	var state State
	foundState := 0
	nin := fnType.NumIn()
	for i := 0; i < nin; i++ {
		if fnType.In(i) == reflect.TypeOf(state) {
			foundState++
		} else if fnType.In(i) == reflect.TypeOf(&state) {
			return false, fmt.Errorf("raw function can not use `*State' as arg, instead using `State'")
		}
	}

	wrongRawFunc := false
	if foundState > 1 {
		wrongRawFunc = true
	} else if foundState == 1 {
		nout := fnType.NumOut()
		if nin != 1 || nout != 1 {
			wrongRawFunc = true
		} else {
			if fnType.Out(0).Kind() != reflect.Int {
				wrongRawFunc = true
			}
		}
	}

	if wrongRawFunc {
		return false, fmt.Errorf("raw function must be type: `func(State) int'")
	}

	return true, nil
}
開發者ID:hxyxj,項目名稱:goinfi,代碼行數:32,代碼來源:lua.go

示例13: BuildArgs

// BuildArgs creates an args slice than can be used to make a f.Call(args)
func BuildArgs(t crossdock.T, desc string, ft reflect.Type, give []interface{}, initialArgs int) (_ []reflect.Value, ok bool) {
	check := crossdock.Checks(t)
	wantIn := len(give) + initialArgs // +2 for ctx and reqMeta
	if !check.Equal(wantIn, ft.NumIn(), "%v: should accept %d arguments", desc, wantIn) {
		return nil, false
	}

	var args []reflect.Value
	for i, v := range give {
		var val reflect.Value
		vt := ft.In(i + initialArgs)
		if v == nil {
			// nil is an invalid argument to ValueOf. For nil, use the zero
			// value for that argument.
			val = reflect.Zero(vt)
		} else {
			val = reflect.ValueOf(v)
		}
		if !check.Equal(vt, val.Type(), "%v: argument %v type mismatch", desc, i) {
			return nil, false
		}
		args = append(args, val)
	}

	return args, true
}
開發者ID:yarpc,項目名稱:yarpc-go,代碼行數:27,代碼來源:behavior.go

示例14: createArguments

// Get all the parameters setup for invocation.
func (method ApiMethod) createArguments(userId UserId, userName UserName, token Token, response http.ResponseWriter, request *http.Request) (bool, []reflect.Value) {
	var handlerType reflect.Type = reflect.TypeOf(method.handler)
	var numParams int = handlerType.NumIn()

	var apiParamIndex = 0
	var paramValues []reflect.Value = make([]reflect.Value, numParams)

	for i := 0; i < numParams; i++ {
		var ParamType reflect.Type = handlerType.In(i)

		// The user id, token, request, and response get handled specially.
		if method.auth && ParamType.String() == "goapi.Token" {
			paramValues[i] = reflect.ValueOf(token)
		} else if method.auth && ParamType.String() == "goapi.UserId" {
			paramValues[i] = reflect.ValueOf(userId)
		} else if method.auth && ParamType.String() == "goapi.UserName" {
			paramValues[i] = reflect.ValueOf(userName)
		} else if ParamType.String() == "*http.Request" {
			paramValues[i] = reflect.ValueOf(request)
		} else if ParamType.String() == "http.ResponseWriter" {
			paramValues[i] = reflect.ValueOf(response)
		} else {
			// Normal param, fetch the next api parameter and pass it along.
			ok, val := method.fetchParam(apiParamIndex, request)
			if !ok {
				return false, []reflect.Value{}
			}

			paramValues[i] = val
			apiParamIndex++
		}
	}

	return true, paramValues
}
開發者ID:eriq-augustine,項目名稱:goapi,代碼行數:36,代碼來源:apimethod.go

示例15: args

func args(f reflect.Type) []reflect.Type {
	in := make([]reflect.Type, f.NumIn())
	for i := 0; i < f.NumIn(); i++ {
		in[i] = f.In(i)
	}
	return in
}
開發者ID:thriftrw,項目名稱:thriftrw-go,代碼行數:7,代碼來源:one.go


注:本文中的reflect.Type.NumIn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。