登录
首页 >  Golang >  Go问答

helm 中的“if 和 (ne)”运算符如何工作?

来源:stackoverflow

时间:2024-04-01 21:09:34 193浏览 收藏

小伙伴们对Golang编程感兴趣吗?是否正在学习相关知识点?如果是,那么本文《helm 中的“if 和 (ne)”运算符如何工作?》,就很适合你,本篇文章讲解的知识点主要包括。在之后的文章中也会多多分享相关知识点,希望对大家的知识积累有所帮助!

问题内容

我正在使用一个一开始就具有以下结构的图表,但我很难理解它何时计算为 true。

{{- if and .Values.vpceIngress.enabled .Values.http.paths (ne .Values.vpceIngress.class "traefik2") }}

我相信 enabledpaths 一定都是 true,但是 ne 之后让我失望。


解决方案


andnego templates 中的函数。

and
    returns the boolean and of its arguments by returning the
    first empty argument or the last argument, that is,
    "and x y" behaves as "if x then y else x". all the
    arguments are evaluated.
ne
    returns the boolean truth of arg1 != arg2

所以模板行相当于一个更伪的codish

if (
  .Values.vpceIngress.enabled
  && .Values.http.paths
  && .Values.vpceIngress.class != "traefik2"
)

普通 .value.key 的真实性基本上是“这个字段/键是 not the zero value for the data type。这也适用于映射,因为“这个字段/键是否已定义”,因为没有该路径的映射等于 nil 或非value(注意,这仅在实际定义了父地图时才有效!否则模板错误)

今天关于《helm 中的“if 和 (ne)”运算符如何工作?》的内容介绍就到此结束,如果有什么疑问或者建议,可以在golang学习网公众号下多多回复交流;文中若有不正之处,也希望回复留言以告知!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>