marshalForMethod returns the map key and the map value for marshalling the method. It returns ("", nil, nil) for valid but non-marshallable parameter. (e.g. "unexportedFunc()")
(typ reflect.Method, val reflect.Value)
| 53 | // marshalForMethod returns the map key and the map value for marshalling the method. |
| 54 | // It returns ("", nil, nil) for valid but non-marshallable parameter. (e.g. "unexportedFunc()") |
| 55 | func marshalForMethod(typ reflect.Method, val reflect.Value) (string, any, error) { |
| 56 | if val.Kind() != reflect.Func { |
| 57 | return "", nil, fmt.Errorf("expected func, got %v", val.Kind()) |
| 58 | } |
| 59 | name, numIn, numOut := typ.Name, val.Type().NumIn(), val.Type().NumOut() |
| 60 | _, blackListed := unmarshallableNames[name] |
| 61 | // FIXME: In text/template, (numOut == 2) is marshallable, |
| 62 | // if the type of the second param is error. |
| 63 | marshallable := unicode.IsUpper(rune(name[0])) && !blackListed && |
| 64 | numIn == 0 && numOut == 1 |
| 65 | if !marshallable { |
| 66 | return "", nil, nil |
| 67 | } |
| 68 | result := val.Call(make([]reflect.Value, numIn)) |
| 69 | intf := result[0].Interface() |
| 70 | return name, intf, nil |
| 71 | } |
no test coverage detected
searching dependent graphs…