func checkProcessingUnfolder()

in gotype/unfold_user.go [154:202]


func checkProcessingUnfolder(fn reflect.Value) error {
	if fn.Kind() != reflect.Func {
		return fmt.Errorf("processing unfolder '%v' is no function", fn)
	}

	t := fn.Type()

	// check input
	if t.NumIn() != 1 {
		return fmt.Errorf("processing unfolder '%v' must accept one target argument", fn)
	}
	in := t.In(0)
	if in.Kind() != reflect.Ptr {
		return fmt.Errorf("processing unfolder '%v' target argument must be a pointer", fn)
	}

	// check returns
	if t.NumOut() != 2 {
		return fmt.Errorf("processing unfolder '%v' must return 2 values", fn)
	}
	if t.Out(0) != tInterface {
		return fmt.Errorf("processing unfolder '%v' must return interface{} as first value", fn)
	}
	proc := t.Out(1)
	if proc.Kind() != reflect.Func {
		return fmt.Errorf("processing unfolder '%v' second return must be a function", fn)
	}

	// check processing function input
	if proc.NumIn() != 2 {
		return fmt.Errorf("processing function of '%v' must accept 2 arguments", fn)
	}
	if proc.In(0) != in {
		return fmt.Errorf("processing function of '%v' must accept the target type '%v'", fn, in)
	}
	if proc.In(1) != tInterface {
		return fmt.Errorf("processing function of '%v' must accept interface{} as second argument", fn)
	}

	// check processing function output
	if proc.NumOut() != 1 {
		return fmt.Errorf("processing function of '%v' must return exactly one value", fn)
	}
	if proc.Out(0) != tError {
		return fmt.Errorf("processing function of '%v' must return an error value", fn)
	}

	return nil
}