0

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.

Aleš
  • 8,896
  • 8
  • 62
  • 107
  • You asked this question [on the bug tracker](https://github.com/google/go-jsonnet/issues/223) and got an answer there. Why did you then come to Stack Overflow and ask the same question? – abarnert May 17 '18 at 22:43
  • Although I asked there I believe its more suitable question for stack overflow. Bug tracker is more for tracking bugs and questions like this will get lost there. I believe the `jsonnet` tag here deserves more activity. – Aleš May 17 '18 at 23:10
  • You seem to be either suggesting that a new feature should be added to some library, or asking for a tutorial on how to use a feature (which you got on the bug tracker), or asking for the latter if it exists and the former if it doesn't. None of those is an appropriate question for SO. – abarnert May 17 '18 at 23:11
  • I am not asking for a tutorial nor for a new feature, I am asking to find out if its possible with the current system. – Aleš May 17 '18 at 23:13
  • Also, I asked here first and did not get a response, then I asked in the bug tracker. – Aleš May 17 '18 at 23:17

1 Answers1

2

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Aleš
  • 8,896
  • 8
  • 62
  • 107