如何将golang变量设置为模板变量

I am new to golang and want to understand how to assign a template variable in golang using the golang variable.

I am using go-swagger to generate go code.

Below is the piece of a customized template to generate my swagger client.

func demo() {
 {{range .Operations}}
   Value := main.CheckAvail(*{{.Package}}.{{ pascalize .Name }})
   {{$value := .Value}}
   {{if $value }}
      {{ pascalize .Name }}
   {{end}}
 {{end}}
}

But it gives me the error that:

" <.Value>: can't evaluate field Value in type generator.GenOperation ".

How do I assign the value to the $value? Any help?

This is not possible. The template file is a wire frame for a go file. It just generates a file of go code, which is not executed yet.

All in {{ ... }} is evaluated, when the template is parsed. At this point, all text outside the curly braces is just plain text. After the (successful) execution of the template generation the generated text will be picked up by the go compiler and compiled (if it is correct go code).

In this case you cannot evaluate Value.