Skip to content

Commit 7dc97cc

Browse files
authored
Update README.md
1 parent 17c7a00 commit 7dc97cc

File tree

1 file changed

+53
-7
lines changed

1 file changed

+53
-7
lines changed

README.md

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,70 @@ A tool to read and modify Base64 encoded JSON to use configurations JSON-files f
44
## To install
55
[Go](https://golang.org/dl/) has to be installed.
66
```shell
7-
go get github.com/palchukovsky/json-env
7+
go get github.com/palchukovsky/json-env
88
```
99
## Examples
1010
### Set value
1111
```shell
12-
json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoidmFsMSJ9fX0 -write "x/y/z=1 2 3" z=valX
12+
json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoidmFsMSJ9fX0 -write "x/y/z=1 2 3" z=valX
1313
```
1414
### Read value
1515
```shell
16-
json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoiMSAyIDMifX0sInoiOiJ2YWxYIn0 -read x/y/z
17-
json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoiMSAyIDMifX0sInoiOiJ2YWxYIn0 -read z
18-
json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoiMSAyIDMifX0sInoiOiJ2YWxYIn0 -read zz -default "is not existent"
16+
json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoiMSAyIDMifX0sInoiOiJ2YWxYIn0 -read x/y/z
17+
json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoiMSAyIDMifX0sInoiOiJ2YWxYIn0 -read z
18+
json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoiMSAyIDMifX0sInoiOiJ2YWxYIn0 -read zz -default "is not existent"
1919
```
2020
### Export source
2121
```shell
22-
json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoiMSAyIDMifX0sInoiOiJ2YWxYIn0 -export
22+
json-env -source eyJmIjoidmFsMiIsIngiOnsieSI6eyJ6IjoiMSAyIDMifX0sInoiOiJ2YWxYIn0 -export
2323
```
2424
### Encode JSON-file to Base64
2525
```shell
26-
json-env -encode_file /path/config.json
26+
json-env -encode_file /path/config.json
27+
```
28+
### Use-case example
29+
```Makefile
30+
CONFIG ?= $(shell json-env -encode_file ./.config.json)
31+
AWS_APP_GATEWAY_ID := $(shell json-env -source ${CONFIG} -read service/aws/gateway/app/id)
32+
AWS_REGION := $(shell json-env -source ${CONFIG} -read service/aws/region)
33+
CONFIG := $(shell json-env -source ${CONFIG} -write \
34+
"build/version=${VERSION}" \
35+
"build/commit=${COMMIT}" \
36+
"build/id=${BUILD}" \
37+
"build/builder=${BUILDER}" \
38+
"build/maintainer=${MAINTAINER}" \
39+
"service/aws/gateway/app/endpoint=${AWS_APP_GATEWAY_ID}.execute-api.${AWS_REGION}.amazonaws.com/${VERSION}")
40+
AWS_ACCESS_KEY_ID := $(shell json-env -source ${CONFIG} -read builder/aws/accessKey/id)
41+
AWS_SECRET_ACCESS_KEY := $(shell json-env -source ${CONFIG} -read builder/aws/accessKey/secret)
42+
AWS_ACCOUNT_ID := $(shell json-env -source ${CONFIG} -read service/aws/accountId)
43+
AWS_AUTH_GATEWAY_ID := $(shell json-env -source ${CONFIG} -read service/aws/gateway/auth/id)
44+
45+
define create-config-file
46+
-mkdir -p ${1}
47+
@echo "json-env -source CONFIG -export > ${1}config.json"
48+
@json-env -source ${CONFIG} -export > "${1}config.json"
49+
endef
50+
```
51+
``` go
52+
func newService(projectPackage string) service {
53+
name := os.Args[0]
54+
55+
var config Config
56+
{
57+
file, err := ioutil.ReadFile("./lambda_config.json")
58+
if err != nil {
59+
log.Fatalf(`Failed to read config file: "%v".`, err)
60+
}
61+
if err := json.Unmarshal(file, &config); err != nil {
62+
log.Fatalf(`Failed to parse config file: "%v".`, err)
63+
}
64+
}
65+
66+
return service{
67+
name: name,
68+
log: newProductLog(projectPackage, name, config),
69+
config: config.Service,
70+
build: config.Build,
71+
}
72+
}
2773
```

0 commit comments

Comments
 (0)