Standard library / html/template
html/template.JSStr
Trusted JavaScript string content, without surrounding quotes; not arbitrary user input. Expected stdout: '<script>let s="fixed";</script>\n'.
Formal Syntax & Structure
go syntaxgo
type JSStr stringWorking Example
Example Snippetgo
package main
import ( "fmt" "html/template" "os")
func check(e error) { if e != nil { panic(e) }}
func main() { t := template.Must(template.New("x").Parse("<script>let s=\"{{.}}\";</script>")) check(t.Execute(os.Stdout, template.JSStr("fixed"))) fmt.Println()}