|
|
9 ماه پیش | |
|---|---|---|
| .. | ||
| LICENSE.txt | 9 ماه پیش | |
| README.md | 9 ماه پیش | |
| env.go | 9 ماه پیش | |
| interpolate.go | 9 ماه پیش | |
| parser.go | 9 ماه پیش | |
A Go library for parameter expansion (like ${NAME} or $NAME) in strings from environment
variables. An implementation of POSIX Parameter
Expansion,
plus some other basic operations that you'd expect in a shell scripting environment like
bash.
go get github.com/mfridman/interpolate@latest
package main
import (
"github.com/mfridman/interpolate"
"fmt"
)
func main() {
env := interpolate.NewSliceEnv([]string{
"NAME=James",
})
output, _ := interpolate.Interpolate(env, "Hello... ${NAME} welcome to the ${ANOTHER_VAR:-🏖}")
fmt.Println(output)
// Output: Hello... James welcome to the 🏖
}
${parameter} or $parameter
${parameter:-[word]}
${parameter-[word]}
${parameter:[offset]}
${parameter:[offset]:[length]}
${parameter:?[word]}
This repository is a fork of buildkite/interpolate. I'd like to thank the authors of that library for their work. I've forked it to make some changes that I needed for my own use cases, and to make it easier to maintain. I've also added some tests and documentation.
Licensed under MIT license, in LICENSE.