How to convert reflect.Value to time.Time

2,681 views
Skip to first unread message

Go newbie

unread,
Feb 12, 2014, 1:03:14 AM2/12/14
to golan...@googlegroups.com
Hi All,

http://play.golang.org/p/ux3iiizTRx

//panic: reflect.Value.Interface: cannot return value obtained from unexported field or method

Thanks in advance.

Best Regards


Ian Lance Taylor

unread,
Feb 12, 2014, 1:43:00 AM2/12/14
to Go newbie, golang-nuts
On Tue, Feb 11, 2014 at 10:03 PM, Go newbie <servic...@gmail.com> wrote:
>
> http://play.golang.org/p/ux3iiizTRx
>
> //panic: reflect.Value.Interface: cannot return value obtained from
> unexported field or method

I'm not sure there is a way to do this. The reflect package by design
does not let you do anything to a struct with unexported fields that
might permit you to change the fields.

Ian

Moises Soto

unread,
Aug 20, 2019, 11:39:10 PM8/20/19
to golang-nuts
Well, this is really old but I had the same problem and its because you need to export the field on YOUR struct (time.Time doesn't needs to have exported fields like someone else said).

Here's the same code with element t time.Time declared as T time.Timehttps://play.golang.org/p/tXh2LqT8s7S
Reply all
Reply to author
Forward
0 new messages