jeudi 20 août 2020

Can I check if a function exists in a Go template?

Go templates as per the text/template package can use functions (some builtins, some injected by the rendering logic). Is it possible to check for the existence of a function (as trying to use one that doesn't exist will result in an unrecoverable rendering error)?

The specific use case is a helm template where I would like to make use of the lookup function opportunistically, without breaking support for Helm versions pre-3.1. It looks like this isn't possible (neither is checking the Helm version - orthogonal issue as this is completely Helm's fault), which is a problem as it prevents me from writing portable charts that make use of newer features, without depending on them.





Aucun commentaire:

Enregistrer un commentaire