From: azat Date: Thu, 30 Nov 2017 19:32:39 +0000 (+0300) Subject: os: Add example for Expand function. X-Git-Tag: go1.11beta1~337 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ef99381676fb008d418720a1169184cea21f4bb6;p=gostls13.git os: Add example for Expand function. Change-Id: I581492c29158e57ca2f98b75f47870791965a7ff Reviewed-on: https://go-review.googlesource.com/81155 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/os/example_test.go b/src/os/example_test.go index 5749194871..e21415a3fd 100644 --- a/src/os/example_test.go +++ b/src/os/example_test.go @@ -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}."))