Skip to content

Commit ef99381

Browse files
azat-devbradfitz
authored andcommitted
os: Add example for Expand function.
Change-Id: I581492c29158e57ca2f98b75f47870791965a7ff Reviewed-on: https://go-review.googlesource.com/81155 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 67fe8b5 commit ef99381

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/os/example_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,24 @@ func init() {
8282
os.Unsetenv("GOPATH")
8383
}
8484

85+
func ExampleExpand() {
86+
mapper := func(placeholderName string) string {
87+
switch placeholderName {
88+
case "DAY_PART":
89+
return "morning"
90+
case "USER":
91+
return "Gopher"
92+
}
93+
94+
return ""
95+
}
96+
97+
fmt.Println(os.Expand("Good ${DAY_PART}, $USER!", mapper))
98+
99+
// Output:
100+
// Good morning, Gopher!
101+
}
102+
85103
func ExampleExpandEnv() {
86104
fmt.Println(os.ExpandEnv("$USER lives in ${HOME}."))
87105

0 commit comments

Comments
 (0)