我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

Go具有模板语言吗?

In Puppet it is possible to lookup variables in files using ERBs, e.g.:

<% @values.each do |val| -%>
Some stuff with <%= val %>
<% end -%>

How to do the same using Go?

The question is a bit unclear, but Go has a very powerful template engine built in: https://golang.org/pkg/text/template/

There's even a special HTML extension package of it that does automatic escaping based on context (attributes, tags, text, etc) - https://golang.org/pkg/html/template/

The above example would look something like:

{{ range .Values }}
    Some stuff with {{ . }}
{{ end }}

近期文章

  • 面向对象的实现
  • 去将reflect.Value从字符串转换为int
  • 错误的GET页面请求
  • 如何解决函数中的Go数组大小
  • 如何编写插入golang代码?
  • 将unicode字符存储在golang中
  • goroutine或多线程在golang中不起作用
  • 如何在Go中格式化此字符串
  • Archlinux:golang不能使用go build
  • 在GO中将字符串转换为函数名称? [重复]
  • 如何使用Golang在Linux中获得网络速度
  • 如何从Golang中的URL检索HTML文档大小
  • 写入文件int转换为字符串
  • 如何使用Go将网页内容转换为字符串
  • 创建结构时正确使用接口
  • 如何在Golang中解析巨大的json
  • 从字符串列表转换为go中的接口列表
  • 如何使用go在没有索引名称的情况下将值存储在哈希图中?
  • 在goLang中,谁了解* var.Type
  • 无法解码Gob数据

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华