jsonnet

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

go-jsonnet-func

A collection of jsonnet native functions that can be easily used in tools written in Golang.

Supports the following functions for jsonnet:

  • sha256
  • parseUrl

Sprig functions are supported in experimental stage and can be added to the code generator to enable those.

The following Sprig functions are supported at the moment. This list would cover most of the Sprig functions in the future.

  • upper
  • snakecase
  • camelcase
  • kebabcase
  • decryptAES

Usage

The library can you used to extend jsonnet functionality offered by your application. To install run:

go get -u github.com/harsimranmaan/go-jsonnet-func

It can used in a sample program as shown in the example.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseURL

func ParseURL() *jsonnet.NativeFunction

ParseURL returns a jsonnet function parseUrl which returns a dictionary representing the input url

Example
vm := jsonnet.MakeVM()
vm.NativeFunction(f.ParseURL())
output, _ := vm.EvaluateAnonymousSnippet("main.jsonnet", `local a = std.native("parseUrl")("https://example.com/test?param=1#link"); {out:a}`)
fmt.Println(output)
Output:

{
   "out": {
      "fragment": "link",
      "host": "example.com",
      "hostname": "example.com",
      "opaque": "",
      "path": "/test",
      "port": "",
      "query": "param=1",
      "scheme": "https",
      "userinfo": ""
   }
}

func SHA256

func SHA256() *jsonnet.NativeFunction

SHA256 returns a jsonnet function sha256 which returns the sha256 string representation of the input value

Example
vm := jsonnet.MakeVM()
vm.NativeFunction(f.SHA256())
output, _ := vm.EvaluateAnonymousSnippet("main.jsonnet", `local a = std.native("sha256")("test"); {out:a}`)
fmt.Println(output)
Output:

{
   "out": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
}

func SprigFuncs added in v0.0.2

func SprigFuncs() []*jsonnet.NativeFunction
Example
vm := jsonnet.MakeVM()
for _, f := range f.SprigFuncs() {
	vm.NativeFunction(f)
}
output, err := vm.EvaluateAnonymousSnippet("main.jsonnet", `local a = std.native("sprig.hello")();
	local b = std.native("sprig.upper")("hSm");
	local c = std.native("sprig.decryptAES")("secretkey", "30tEfhuJSVRhpG97XCuWgz2okj7L8vQ1s6V9zVUPeDQ=");

	[a,b,c]`)
if err != nil {
	fmt.Println(err)
}
fmt.Println(output)
Output:

[
   "Hello!",
   "HSM",
   "plaintext"
]

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL