From ef99381676fb008d418720a1169184cea21f4bb6 Mon Sep 17 00:00:00 2001 From: azat Date: Thu, 30 Nov 2017 22:32:39 +0300 Subject: [PATCH] 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 --- src/os/example_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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}.")) -- 2.50.0