Go templates with eq and index -


go templates have unexpected results when using eq index me. see code:

package main  import (     "os"     "text/template" )  func main() {     const mytemplate = ` {{range $n := .}}     {{index $n 0}} {{if (index $n 0) eq (index $n 1)}}={{else}}!={{end}} {{index $n 1}} {{end}} `     t := template.must(template.new("").parse(mytemplate))      t.execute(os.stdout,         [][2]int{             [2]int{1, 2},             [2]int{2, 2},             [2]int{4, 2},         })  } 

i expect have output

1 != 2 2 = 2 4 != 2 

but

1 = 2 2 = 2 4 = 2 

what should change able compare array members in go templates?

eq prefix operation:

{{if eq (index $n 0) (index $n 1)}}={{else}}!={{end}} 

playground: http://play.golang.org/p/kefxh6s7n1.


Comments

Popular posts from this blog

html - Difficulties with background-image property -

visual studio code - What does the isShellCommand property actually do and how should you use it? -

ios - Segue not passing data between ViewControllers -