Skip to content

proposal: Add support for retrieving function parameter names with reflect #12384

@nenadl

Description

@nenadl

Currently there is no way to retrieve function/method parameter names with the reflect package. The only introspection available is for the types of the input and output parameters of a function. The seems to be an exception with the reflect package, since it does offer naming information in most other cases.

When building RPC/API libraries it is useful to be able to retrieve these method parameters names for purposes of runtime schema output, input validation on unstructured data, and possibly some API semantics. There are some alternatives right now:

  • Parse the source and use code generation to compile this metadata into the running program.
  • Use structs for all input/output and then use the field names in the structs, along with their tags, for introspection.

Some other considerations:

  • I understand that this might lead to binary and/or memory size increase due to the additional metadata that might have to be stored. This change might not be ideal this far into the 1.X cycle, but I think it should at least be considered for 2.0.
  • A fairly straightforward way to do this, that would not break backwards compatibility, would be to add two methods to reflect.Type that would retrieve the In/Out parameter names by Index.

Apologies if this is a duplicate issues. I searched the forums (nuts/dev) and this issue tracker and could not find any previous issues filed on this topic.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions