02 模板语法GoTemplate
1 | func (t *Template) Parse(src string) (*Template, error) |
1 | func(t *Template) Execute(wr io.Writer, data interface) error |
1 |
|
1 | // main.go |
1 | // main.go |
1 |
|
1 | {{/* a comment */}} |
1 | $obj := {{.}} |
1 | {{- .Name -}} |
1 | {{if pipeline}} T1 {{end}} |
1 | {{range pipeline}}T1{{end}} |
1 | {{with pipeline}}T1{{end}} |
1 | and |
1 | eq 如果arg1 == arg2则返回真 |
1 | {{eq arg1 arg2 arg3}} |
1 | func sayHello(w http.ResponseWriter, r *http.Request) { |
1 | {{kua .Name}} |
1 |
|
1 | <ul> |
1 | http.HandleFunc("/tmpl", tmplDemo) |
1 | func tmplDemo(w http.ResponseWriter, r *http.Request) { |
1 | {{block "name" pipeline}} T1 {{end}} |
1 |
|
1 | {{template "base.tmpl"}} |
1 | func index(w http.ResponseWriter, r *http.Request){ |
1 | template.New("test").Delims("{[", "]}").ParseFiles("./t.tmpl") |
1 |
|
1 | func xss(w http.ResponseWriter, r *http.Request){ |
1 | {{ . | safe }} |
1 | {{required "A valid foo is required!" .Values.foo }} |
1 | {{include "toYaml" $value | indent 2 }} |
1 | # values |
1 | # external configuration file conf/app.conf |
1 | (lookup "v1" "Namespace" "" "mynamespace").metadata.annotations |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 Estom的博客!




