Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Function 在if语句中使用函数return或在go模板中使用变量_Function_Templates_Go - Fatal编程技术网

Function 在if语句中使用函数return或在go模板中使用变量

Function 在if语句中使用函数return或在go模板中使用变量,function,templates,go,Function,Templates,Go,我正在使用go模板筛选出使用Consor模板命名不正确的服务。我从领事模板获得了一个函数regexMatch,其工作原理如下: {{"foo.bar" | regexMatch "foo([.a-z]+)"}} {{range services}} {{$service:=.Name}} {{if not (eq $service "consul")}} 它根据字符串返回true或false。我希望在if语句中有条件地使用它,类似于我的其他代码,它过滤掉名为“consur”的服务。其工作原理

我正在使用go模板筛选出使用Consor模板命名不正确的服务。我从领事模板获得了一个函数regexMatch,其工作原理如下:

{{"foo.bar" | regexMatch "foo([.a-z]+)"}}
{{range services}} {{$service:=.Name}} {{if not (eq $service "consul")}}
它根据字符串返回true或false。我希望在if语句中有条件地使用它,类似于我的其他代码,它过滤掉名为“consur”的服务。其工作原理如下:

{{"foo.bar" | regexMatch "foo([.a-z]+)"}}
{{range services}} {{$service:=.Name}} {{if not (eq $service "consul")}}
问题是我不能将函数调用嵌套在if语句或变量声明中。我试过了

{{if {$service | regexMatch "^[-a-z0-9]{1,}$"}}}}

但我有以下错误:

unexpected "{" in if
unexpected bad character U+003D '='

如何在此go模板中的if语句中使用regexMatch函数?

如果有人需要

{{if $service | regexMatch "^[-a-z0-9]{1,}$"}} 

具体而言:

{{pipeline}} 管道值的默认文本表示形式 被复制到输出

{{if pipeline}}T1{{end} 如果管道的值为空,则不生成输出; 否则,执行T1。空值为false、0或任意值 零指针或接口值,以及任何数组、切片、映射或 长度为零的字符串。 圆点不受影响