diff --git a/implementations/Golang_github.com-theory-jsonpath/LINK b/implementations/Golang_github.com-theory-jsonpath/LINK new file mode 100644 index 00000000..17b20a23 --- /dev/null +++ b/implementations/Golang_github.com-theory-jsonpath/LINK @@ -0,0 +1 @@ +https://github.com/theory/jsonpath diff --git a/implementations/Golang_github.com-theory-jsonpath/build.ninja b/implementations/Golang_github.com-theory-jsonpath/build.ninja new file mode 100644 index 00000000..b7c1054c --- /dev/null +++ b/implementations/Golang_github.com-theory-jsonpath/build.ninja @@ -0,0 +1,10 @@ +root = implementations/Golang_github.com-theory-jsonpath +builddir = $root/build + +# Hack target directory because golang is bad, again +rule build + command = cd $root && go build -o build/main + +build $builddir/main: build | $root/main.go $root/go.mod $root/go.sum + +build $root/install: phony $builddir/main diff --git a/implementations/Golang_github.com-theory-jsonpath/go.mod b/implementations/Golang_github.com-theory-jsonpath/go.mod new file mode 100644 index 00000000..7bd3b481 --- /dev/null +++ b/implementations/Golang_github.com-theory-jsonpath/go.mod @@ -0,0 +1,5 @@ +module example.com/main + +go 1.23 + +require github.com/theory/jsonpath v0.10.0 diff --git a/implementations/Golang_github.com-theory-jsonpath/go.sum b/implementations/Golang_github.com-theory-jsonpath/go.sum new file mode 100644 index 00000000..28cadebe --- /dev/null +++ b/implementations/Golang_github.com-theory-jsonpath/go.sum @@ -0,0 +1,10 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/theory/jsonpath v0.10.0 h1:qjuGwjcWMPfYmhjDnOjP9vmGzISeRzQ/87u2GZIWLoA= +github.com/theory/jsonpath v0.10.0/go.mod h1:yv+crL58A+g3yxLr1sbOyn8H+L/6kS4AMXlXeVGOuNU= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/implementations/Golang_github.com-theory-jsonpath/main.go b/implementations/Golang_github.com-theory-jsonpath/main.go new file mode 100644 index 00000000..cbfc3a72 --- /dev/null +++ b/implementations/Golang_github.com-theory-jsonpath/main.go @@ -0,0 +1,42 @@ +// Copyright 2020 VMware, Inc. +// SPDX-License-Identifier: GPL-3.0 + +package main + +import ( + "encoding/json" + "fmt" + "io" + "os" + + "github.com/theory/jsonpath" +) + +func main() { + selector := os.Args[1] + + data, err := io.ReadAll(os.Stdin) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + + var json_data any + if err := json.Unmarshal([]byte(data), &json_data); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(2) + } + + path, err := jsonpath.Parse(selector) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(2) + } + + json_result, err := json.Marshal(path.Select(json_data)) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(2) + } + fmt.Println(string(json_result)) +} diff --git a/implementations/Golang_github.com-theory-jsonpath/run.sh b/implementations/Golang_github.com-theory-jsonpath/run.sh new file mode 100755 index 00000000..9863e699 --- /dev/null +++ b/implementations/Golang_github.com-theory-jsonpath/run.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -euo pipefail + +readonly script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +"$script_dir"/build/main "$@" diff --git a/implementations/Golang_github.com-theory-jsonpath/upgrade.sh b/implementations/Golang_github.com-theory-jsonpath/upgrade.sh new file mode 100755 index 00000000..9a1cb7a0 --- /dev/null +++ b/implementations/Golang_github.com-theory-jsonpath/upgrade.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -euo pipefail + +cd "$(dirname "$BASH_SOURCE[0]")" +go get -u