Let us have some concrete code snippet for discussion:
https://play.golang.org/p/fdcEs3k9U8I

Is this what you would like to have?


On Mon, Jun 3, 2019 at 11:54 AM 杜沁园 <sa517...@mail.ustc.edu.cn> wrote:

> I recently write a program to recursively print all fields and value in a
> struct. Interface() is the most convinence way to get underlying value in
> go.
> But it will panic when field is private.How can I access private field?
>
> For simple type, I can stil use Int(),Bool(),etc to read private field.
>  But if the field is a interface, I do not know how to access is concrete
> value without use Interface() method.
>
>
> For example:
>
> type Expr interface {
>    eval(v string) bool
> }
>
> type MyExpr struct {
>    Haha string
> }
>
>
> type Web struct {
>    Host    string
>    epr     Expr
> }
>
>
>
>
> How can I get Web.Epr Value by reflection without use Interface() method
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/66703aa4-de59-4ae8-8407-928e7ebf95c5%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/66703aa4-de59-4ae8-8407-928e7ebf95c5%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAHS-Gt0z9gCi1dbSOxeXXEXH%3DW-iDNCS4PLdXfi5g%2BivrRPWMw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to