summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorazat <kaumov.a.r@gmail.com>2017-11-30 22:32:39 +0300
committerBrad Fitzpatrick <bradfitz@golang.org>2018-05-23 15:37:22 +0000
commitef99381676fb008d418720a1169184cea21f4bb6 (patch)
tree45c6b71753d22f63d180da307a2106ac5bf10425 /src
parent67fe8b5677c8dca1503550ca72d1e460bca0375c (diff)
downloadgo-git-ef99381676fb008d418720a1169184cea21f4bb6.tar.gz
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>
Diffstat (limited to 'src')
-rw-r--r--src/os/example_test.go18
1 files changed, 18 insertions, 0 deletions
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}."))