how to check empty value of a string in golang template

Here is what you're doing (always better to give an example play.golang.org link if possible):

https://play.golang.org/p/uisbAr_3Qy

A few problems with what you're doing: If you're using a map for context, you don't need to use index at all, so your variables are not required. If you want to check if a key exists, just check for a nil entry with if. If your map contains elements of type interface, you can't compare with a string, only use eq when you're sure you have an element but are not sure what it might be, and wrap it in an if test if unsure whether the key exists.

I think you want to do something like this:

{{if .source }}
  <div style="display:none;">
    <input id="username" name="source" value="{{ .source }}"/>
    <input id="username" name="target" value="{{ .target }}"/>
  </div>
{{else}}
  <div>empty</div>
{{end}}

https://play.golang.org/p/D2DCjAklFE

See the docs for text/template as they have a lot more detail:

https://golang.org/pkg/text/template/#hdr-Actions