FAQ
There is currently no reason for the compiler to store the names of
function args in the compiled code

You must mean, besides reflection? :-)
It doesn't keep the function name either, for that matter.
It doesn't? Then how does this work:

http://golang.org/pkg/reflect/#Value.MethodByName

Field names are available:

http://golang.org/pkg/reflect/#Value.FieldByName

So it would seem argument names may be the exception that confirms the rule
;-)

If what you're saying is the *compiler* doesn't need this information for
*itself*, that may be true - but it would be nice, for the sake of
completeness and consistency in the reflection API, if the names of
arguments could be reflected, same as the names of most other members.

To be fair, const names can't be reflected - but arguably, these are just
symbols and not members per se - arguments do appear to be the only member
type that cannot be reflected?

It seems incomplete without it.

On Wed, Oct 8, 2014 at 6:09 AM, Matt Harden wrote:

It's still not possible, and I wouldn't count on it ever being possible.
There is currently no reason for the compiler to store the names of
function args in the compiled code. It doesn't keep the function name
either, for that matter.

You could write a code generator that works with go generate (1.4+ only -
not released yet) which could read the declaration and create the
implementation automatically for you. go/ast <http://godoc.org/go/ast> can
help you with this. This could also eliminate any slowdown due to
reflection.

On Tue, Oct 7, 2014 at 7:49 PM, wrote:

Damn, I wanted this for self-documenting RPC, still not possible?
On Thursday, 7 June 2012 03:41:33 UTC-7, buzzlight wrote:

Dear all,

Is it possibile to get method parameter name by reflect?

example

there is a method

func (u *user)query(name string, age int) []user {
...
}

http request is : get /api/query?&name=foo&age=18

I want to extract args value from query string and invoke query dynamic
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the
Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/golang-nuts/nM_ZhL7fuGc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 8 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 8, '14 at 2:49a
activeOct 8, '14 at 12:22p
posts8
users5
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase