mirror of
https://github.com/golang/go
synced 2024-11-18 06:44:49 -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:
parent
67fe8b5677
commit
ef99381676
@ -82,6 +82,24 @@ func init() {
|
||||
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() {
|
||||
fmt.Println(os.ExpandEnv("$USER lives in ${HOME}."))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user