Case insensitive string compare in Go template

1,615 views
Skip to first unread message

Tong Sun

unread,
Jul 27, 2015, 10:57:57 PM7/27/15
to golang-nuts
Go template provides an `eq` comparison operator, e.g., `{{if eq .Var "val" }}`. 
What's the best way to do a case insensitive string comparison in this case?
(so that the above would be true for Var to be "val", "Val", or "VAL")

Thanks


Matt Harden

unread,
Jul 27, 2015, 11:10:56 PM7/27/15
to Tong Sun, golang-nuts
You would need to provide a function, either to compare strings case-insensitively, or to convert strings to lower case. See http://godoc.org/text/template#example-Template--Func for an example of a function.

--
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.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages