Urlencode function for templates?

I need to call a webhook for one of our contact points. It’s and SMS service with an API. I need to send the message URLencoded, in particular {{ URLEncode (index $annotations "subject") }} or something would be awesome. Any hints?

It would also be nice to have a function to edit the params of an URL, for instance to replace the default params for SilenceURL.

Workaround: many reReplaceAlls, where you encode all special characters manually. Yes, not perfect, but at least something.
Or just create another own webhook, where you do url encoding, before passing to final webhook.

I guess/hope that the webhook would receive the data some other way. Where can i find docs about implementing such a webhook?

Seems like there is a function called urlencode ready for this: template package - text/template - Go Packages

Please prove it.

I tried:

http://x.y.z.w:5000/?foo={{ urlencode .CommonAnnotations.summary }}

got bad news:

Failed to send test alert.: template: :1: function "urlencode" not defined

Ah, typo, who the hell calls it urlquery?!?! :^D

Returns the escaped value of the textual representation of its arguments in a form suitable for embedding in a URL query. This function is unavailable in html/template, with a few exceptions.

1 Like