1
0
mirror of https://github.com/golang/go synced 2024-11-18 08:24:44 -07:00

os: Add example for Expand function.

Change-Id: I581492c29158e57ca2f98b75f47870791965a7ff
Reviewed-on: https://go-review.googlesource.com/81155
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
azat 2017-11-30 22:32:39 +03:00 committed by Brad Fitzpatrick
parent 67fe8b5677
commit ef99381676

View File

@ -82,6 +82,24 @@ func init() {
os.Unsetenv("GOPATH") os.Unsetenv("GOPATH")
} }
func ExampleExpand() {
mapper := func(placeholderName string) string {
switch placeholderName {
case "DAY_PART":
return "morning"
case "USER":
return "Gopher"
}
return ""
}
fmt.Println(os.Expand("Good ${DAY_PART}, $USER!", mapper))
// Output:
// Good morning, Gopher!
}
func ExampleExpandEnv() { func ExampleExpandEnv() {
fmt.Println(os.ExpandEnv("$USER lives in ${HOME}.")) fmt.Println(os.ExpandEnv("$USER lives in ${HOME}."))