https://github.com/nissy/envexpand
envexpand recursively replaces strings with environment variables.
https://github.com/nissy/envexpand
environment environment-variables go
Last synced: about 1 year ago
JSON representation
envexpand recursively replaces strings with environment variables.
- Host: GitHub
- URL: https://github.com/nissy/envexpand
- Owner: nissy
- License: mit
- Created: 2019-01-31T15:38:34.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-18T15:09:37.000Z (almost 7 years ago)
- Last Synced: 2025-05-12T22:59:44.902Z (about 1 year ago)
- Topics: environment, environment-variables, go
- Language: Go
- Homepage:
- Size: 44.9 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# envexpand
envexpand is replace placeholders in strings recursively with environment variables.
### install
```bash
$ go get -u github.com/nissy/envexpand
```
### example
environment variable placeholder.
`${VARIABLE_NAME}`
```go
package main
import "github.com/nissy/envexpand"
type (
ABC struct {
A string
B []string
C map[int]string
D *D
}
D struct {
E string
F *F
}
F struct {
G int
H string
I []*I
}
I struct {
J string
K []map[int]string
L []string
}
)
func main() {
data := ABC{
A: "${A}",
B: []string{
"${B}",
"${B}",
"${B}",
},
D: &D{
F: &F{
I: []*I{
{
J: "${J}",
},
{
J: "${J}",
K: []map[int]string{
{
1: "${K}",
2: "${K}",
},
},
L: []string{
"${L}",
"${L}",
},
},
},
},
},
}
if err := envexpand.Do(&data); err != nil {
panic(err)
}
}
```
```bash
$ echo A=$A B=$B J=$J K=$K L=$L
A=AAAAA B=BBBBB J=JJJJJ K=KKKKK L=LLLLL
```
```
main.ABC{
A: "AAAAA",
B: []string{
"BBBBB",
"BBBBB",
"BBBBB",
},
C: map[int]string{},
D: &main.D{
E: "",
F: &main.F{
G: 0,
H: "",
I: []*main.I{
&main.I{
J: "JJJJJ",
K: []map[int]string{},
L: []string{},
},
&main.I{
J: "JJJJJ",
K: []map[int]string{
map[int]string{
1: "KKKKK",
2: "KKKKK",
},
},
L: []string{
"LLLLL",
"LLLLL",
},
},
},
},
},
}
```