Install Javonet for GoLang
Javonet is available as a GoLang library and can be downloaded after registering.
Activate Javonet
Use register or log in pages to obtain license key. An e-mail and license key is necessary to activate Javonet.
First sample application
Javonet needs to be imported as any other dependency.
import Javonet "javonet.com/javonet"
Javonet needs to be activated first. Activation must be called only once at the start-up of an application. During the first activation, license server are called and a javonet.lic file is generated.
Javonet.ActivateWithCredentials("your-license-key");
To use other programming technology, Runtime Context of the called technology needs to be created.
pythonRuntime := Javonet.InMemory().Python();
RuntimeContext refers to single instance of the called runtime. Once it is created it is used to interact with called runtime. The simplest use case is to get from target technology a type from a built-in library:
pythonType := pythonRuntime.GetType("math").Execute();
And then get static field from the type:
response := pythonType.GetStaticField("pi").Execute()
The returned value needs to be cast to calling technology type and can be used as any other variable:
result := response.GetValue().(float32)
fmt.Println(result)
To sum up, the whole code snippet looks like:
// <Activation>
Javonet.ActivateWithCredentials("your-license-key");
// </Activation>
// <RuntimeContextCreation>
pythonRuntime := Javonet.InMemory().Python();
// </RuntimeContextCreation>
// <GetType>
pythonType := pythonRuntime.GetType("math").Execute();
// </GetType>
// <GetStaticField>
response := pythonType.GetStaticField("pi").Execute()
// </GetStaticField>
// <GetValue>
result := response.GetValue().(float32)
fmt.Println(result)
// </GetValue>
Was this article helpful?