golang template包的使用:解决多行字符串在yaml文件中的缩进问题

代码

workflowtemplate, err := template.New("workflowtemplate.gotmpl").Funcs(sprig.TxtFuncMap()).Funcs(funcMap).ParseFiles(os.Getenv("GT_TEMPLATE_PATH")+"/workflowtemplate.gotmpl")

.Funcs(sprig.TxtFuncMap())引自包:
import "github.com/Masterminds/sprig/v3"

使用

nindent 10表示缩进10个空格

source: |
          {
   
   {- .Source | nindent 10 }}

效果

已经成功实现了缩进:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/a772304419/article/details/124819896
今日推荐