New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove function in KV is hard to use from templates #3393
Comments
Looking at 66a0ed2 , stringSlice was added exactly for this use case.
IIUC Remove is expected to take a KV.Names (or KV.Values) as input. I agree that a note in the documentation of Remove mentioning stringSlice would help. |
If that's the expected use case then I think what's missing is documentation showing situations where using For example, as far as I can see the only way you can use
But how useful is that? I couldn't find any functions that operate on
Instead, if I just want to remove the summary annotation I need to do something like:
when instead I could do:
That is to say I don't see what use cases are made possible by having |
Problem
This week I was attempting to write an Alertmanager template that printed the Summary, Description and Runbook URL annotations, followed by any additional annotations indented under the title
Annotations:
. For example:Such templates should be straightforward to write, however I struggled for about an hour or so on how use the
Remove
method onKV
in a Go template, which is necessary to remove the Summary, Description and Runbook URL annotations from the list of remaining annotations that will be printed at the end.The following doesn't work:
because the problem here is that
Remove
expects an[]string
, rather than a variadic argument of...string
:How does one create a
[]string
in a Go template? You can't - at least not without a helper function that turns...string
into[]string
.It turns out that Alertmanager has a
stringSlice
function, but it's right at the bottom of the page. That being said, it works:and I was able to create the template I wanted:
Questions
Remove
to require[]string
instead of...string
when so much of Go template is designed around variadic arguments? For example:Remove
?The text was updated successfully, but these errors were encountered: