This Go code always quotes a string: http://play.golang.org/p/8k4s8dv2PE in the template - you can see results. How can I generate var currentUser = null
? Note it also removes all comments from the code! How is it tuned up? This question is continuation of my Go: quoted string in templates.
相关问题
- Golang mongodb aggregation
- How to flatten out a nested json structure in go
- how to install private repo using glide golang
- How to convert a string to a byte array which is c
- IntelliJ 2017.1.2 GOLANG debug does not work on br
The
html/template
package is expressly designed to escape values. In your case, you're trying to pass JavaScript code in, rather than a simple value. You can accomplish this by changing the type ofUserEmail
to that oftemplate.JS
. This type wraps astring
and expresses the intent that this value is valid JavaScript and should be substituted directly (without quotes) when used in a JavaScript context.This version of the code does precisely that: http://play.golang.org/p/aNGnFMyY1O