Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case insensitive string compare in Go template

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".

like image 866
xpt Avatar asked May 12 '26 09:05

xpt


1 Answers

You can simply create another lowercase variable s1 := strings.ToLower(s) and to compare it with your template against a lowercase string.

like image 80
Salvador Dali Avatar answered May 14 '26 06:05

Salvador Dali