Non-alphanumerics in template field names?

69 views
Skip to first unread message

Bob DuCharme

unread,
Jul 31, 2020, 12:17:03 PM7/31/20
to golang-nuts
I have seen that a map key name of "foo:bar" works just fine... unless I reference it in a template. {{.foo:bar}} gives me a segmentation violation at runtime, but works fine if there was no colon in the map key name. I have tried various ways to escape the colon or quote the field name (e.g. {{."foo:bar"}}, {{.foo%3Abar}} ) with no luck. 

Does anyone know a way to allow non-alphanumeric characters (besides the underscore, which I know works) in names that get referenced in templates? 

Thanks,

Bob

roger peppe

unread,
Aug 1, 2020, 12:00:01 PM8/1/20
to Bob DuCharme, golang-nuts
You could use the "index" built-in function instead of the dot operator:

{{index . "foo:bar"}}

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/ec64bc07-52a8-429d-bf13-7853da959925n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages