gpt4 book ai didi

templates - 如何使用文本/模板包评估字段?走

转载 作者:数据小太阳 更新时间:2023-10-29 03:17:01 26 4
gpt4 key购买 nike

我有一个模板,我想使用 text/template 评估各个字段包裹。我很难弄清楚评估应该如何工作,因为下面的代码似乎失败了。模板包是否足够强大以处理此类评估?

type something struct{
Brand string
}
tpl := `{{if .Brand == "Coke"}} It's a coke{{else}} It's something else{{end}}`

最佳答案

模板包中有一个名为eq 的全局函数,您可以调用它。不知道为什么会这样,但这是代码

type something struct{
Brand string
}
tpl := `{{if eq .Brand "Coke"}} It's a coke{{else}} It's something else{{end}}`

关于templates - 如何使用文本/模板包评估字段?走,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28930267/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com