Search code examples
gojsonnet

Custom builtin functions in jsonnet


Is there a way how I can call golang functions from jsonnet?

Now that there is a go port of jsonnet and for example ksonnet is adding custom native functions I am wondering if there is a way how to extend jsonnet with more native functions?

I have many packages written in golang (with unit-testing, etc) and now it seems like I will need to rewrite some of them into jsonnet.


Solution

  • As discussed in the go-jsonnet's issue Custom builtin functions #223, you can introduce your custom golang functions but a pluggable support is not available - you cannot directly use the functions in a jsonnet binary.

    You need to compile your own binary/library that creates an instance of vm.NativeFunction jsonnet VM and then add your native functions there.