Go標准庫提供了兩個模版輸出功能:
- text/template 基於模板輸出文本內容
- html/template 產生安全的HTML格式的輸出(可對抗代碼注入)
要在VSCode編輯時支持模版,就需要用一些VSCode插件了。
推薦的插件:
gotemplate-syntax
它的支持情況如下:

Go Template Support
不過它最新版本有問題,無法啟動,報必須定義 "configuration.semanticTokenType.description" 且它不可為空
關聯文件類型
大家用的模版文件后綴各有不同,
為了更好的支持,需要自行配置后綴映射。
菜單: Preference->Settings子菜單,快捷鍵:⌘+,
然后搜索 files.associations 就可以找到設置。
然后添加 *.tpl gohtml 即可

效果

參考:
