-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 880123c
Showing
8 changed files
with
444 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
uhandles | ||
test/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# | ||
# tiny go builder | ||
# | ||
|
||
FROM ubuntu:20.04 | ||
|
||
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ | ||
golang-go build-essential ca-certificates | ||
|
||
WORKDIR /host | ||
|
||
CMD go get && make build |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
all: | ||
docker build -t uhandles . | ||
docker run --rm -v "${PWD}":/host uhandles | ||
docker rmi uhandles | ||
|
||
build: | ||
go build -o uhandles -tags netgo -installsuffix netgo --ldflags '-w -extldflags "-static"' uhandles.go | ||
|
||
clean: | ||
rm uhandles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# uhandles | ||
|
||
An escalation of [jsonsubst](https://github.com/arbitar/jsonsubst). | ||
Small static Go program with no external runtime dependencies that takes a [handlebars](https://handlebarsjs.com) template in from stdin, renders it with data from a JSON file (passed by argument), and outputs the result to stdout. | ||
This is basically just a simple wrapper around [aymerick/raymond](https://github.com/aymerick/raymond). | ||
|
||
## Usage | ||
Very simple. One argument: JSON file. | ||
|
||
`./uhandles data.json <input.txt >output.txt` | ||
|
||
Or, in a pipeline of some kind... | ||
|
||
`cat input.txt | ./uhandles data.json | tee output.txt` | ||
|
||
## Build | ||
If you're cool and already have a good working Go build environment on your system, just run `make build`. | ||
|
||
I'm not cool though, so I use Docker for this kind of thing, which is why it's the default make target. Just run `make` on a system with Docker running on it, and a build image will be created, `make build` executed within the container where all the prerequisites exist, and the build image will be removed after it's done. | ||
|
||
## Notes | ||
No external runtime dependencies, so it should run anywhere. Which means it'll run inside your quick-and-dirty Docker stuff without complaint. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module github.com/arbitar/uhandles | ||
|
||
go 1.19 | ||
|
||
require github.com/aymerick/raymond v2.0.2+incompatible | ||
|
||
require gopkg.in/yaml.v2 v2.4.0 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
github.com/aymerick/raymond v2.0.2+incompatible h1:VEp3GpgdAnv9B2GFyTvqgcKvY+mfKMjPOA3SbKLtnU0= | ||
github.com/aymerick/raymond v2.0.2+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= | ||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"strings" | ||
|
||
"github.com/aymerick/raymond" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) != 2 { | ||
fmt.Println("Usage: uhandlebars <json file>") | ||
os.Exit(1) | ||
} | ||
|
||
jsonFile := os.Args[1] | ||
|
||
jsonData, err := ioutil.ReadFile(jsonFile) | ||
if err != nil { | ||
fmt.Println("Error reading JSON file:", err) | ||
os.Exit(1) | ||
} | ||
|
||
var data interface{} | ||
err = json.Unmarshal(jsonData, &data) | ||
if err != nil { | ||
fmt.Println("Error parsing JSON file:", err) | ||
os.Exit(1) | ||
} | ||
|
||
template, err := ioutil.ReadAll(os.Stdin) | ||
if err != nil { | ||
fmt.Println("Error reading template from stdin:", err) | ||
os.Exit(1) | ||
} | ||
|
||
result, err := raymond.Render(string(template), data) | ||
if err != nil { | ||
fmt.Println("Error rendering template:", err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println(strings.TrimSpace(result)) | ||
} |