FAQ
I ran across this behavior while working with HTML templates; I have a
struct where one of its methods returns a special value if the receiver is
nil. This seems to be ok in templates unless the receiver is inside a
struct. Example:
http://play.golang.org/p/kI69FMyOkL

I couldn't find this documented anywhere. I did find the code returning the
error; I assume it's because the template package uses reflection under the
hood?

--
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/groups/opt_out.

Search Discussions

  • Matt Harden at Jan 2, 2014 at 1:58 am
    At this line
    https://code.google.com/p/go/source/browse/src/pkg/text/template/exec.go?name=release#462,
    the reflection based code take a pointer to the field even if the field
    contains a pointer already. So I think it's trying to find a method Name()
    on the type (**Inner) instead of just (*Inner). I'd suggest opening a bug
    against the template package.

    By the way, it actually works if o1 is an Outer value rather than a pointer
    (*Outer). That's because it can't take a pointer to the pointer in that
    case:
    http://play.golang.org/p/-FgF-nTs0C

    On Wed, Jan 1, 2014 at 3:36 PM, decitrig wrote:

    I ran across this behavior while working with HTML templates; I have a
    struct where one of its methods returns a special value if the receiver is
    nil. This seems to be ok in templates unless the receiver is inside a
    struct. Example:
    http://play.golang.org/p/kI69FMyOkL

    I couldn't find this documented anywhere. I did find the code returning
    the error; I assume it's because the template package uses reflection under
    the hood?

    --
    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/groups/opt_out.
    --
    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/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 1, '14 at 9:36p
activeJan 2, '14 at 1:58a
posts2
users2
websitegolang.org

2 users in discussion

Matt Harden: 1 post Decitrig: 1 post

People

Translate

site design / logo © 2022 Grokbase