esub
A library to replace string placeholders with environment variables.
Usage
package main
import (
"fmt"
"os"
"github.com/winebarrel/esub"
)
func main() {
os.Setenv("foo", "ZOO")
os.Setenv("BAR", "baz")
tmpl := "foo:${foo} BAR:${BAR}"
out, err := esub.Fill(tmpl)
if err != nil {
panic(err)
}
fmt.Println(out) //=> "foo:ZOO BAR:baz"
}
Escape Placeholders
tmpl := "foo:$${foo} BAR:${BAR}"
// ^^^
out, _ := esub.Fill(tmpl)
fmt.Println(out) //=> "foo:${foo} BAR:baz"