jqbuiltin

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: BSD-3-Clause-Clear Imports: 8 Imported by: 0

README

Testing an OPA builtin with a rego query

  1. Set up your main.go to be the following
func main() {
	logLevel := &slog.LevelVar{}
	logLevel.Set(slog.LevelDebug)

	opts := &slog.HandlerOptions{
		Level: logLevel,
	}
	logger := slog.New(slog.NewJSONHandler(os.Stdout, opts))

	slog.SetDefault(logger)

	jqbuiltin.JQBuiltin()

	if err := cmd.RootCommand.Execute(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
  1. Build the executable
cd service
go build -o opa++
  1. Create an example rego file
package sample

my_json = {
  "testing1": {
    "testing2": {
      "testing3": ["helloworld"]
    }
  }
}
req = ".testing1.testing2.testing3[]"

res := jq.evaluate(my_json, req)
  1. Perform the query
./opa++ eval -d example.rego 'data.sample.res'

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteQuery

func ExecuteQuery(inputJSON map[string]any, queryString string) ([]any, error)

func JQBuiltin

func JQBuiltin()

Types

This section is empty.

Jump to

Keyboard shortcuts

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