reflect, is it possible to get the [body + sign] of a func as text at runtime ?

110 views
Skip to first unread message

mhhcbon

unread,
Sep 17, 2016, 6:53:35 AM9/17/16
to golang-nuts
Hi,

i m wondering if one can use reflect to extract at runtime the body and and signature of a Func or 'Public method' ?
Will a reflect.Value.String of a Method give me that data ?

https://golang.org/pkg/reflect/#Method

Will that work on a compiled binary ? (An environment where the raw source code does not exists)

Alternatively, can runtime give me a location information to use with a sort of go code parser to extract that data ?
Assuming in this case i have the raw source code.

thanks

aro...@gmail.com

unread,
Sep 17, 2016, 5:09:44 PM9/17/16
to golang-nuts
Use the Type: reflect.Value.Type.String: https://play.golang.org/p/dlwjCROG6H

Mihai B

unread,
Sep 18, 2016, 3:22:39 AM9/18/16
to golang-nuts
The body is compiled so you can't get it via reflection.

mhhcbon

unread,
Sep 18, 2016, 5:27:03 AM9/18/16
to golang-nuts
Hi,

 thanks both of you for your confirmation.

I ll evaluate alternatives.
Reply all
Reply to author
Forward
0 new messages