diff options
author | Corey Hulen <corey@hulen.com> | 2017-03-24 23:31:34 -0700 |
---|---|---|
committer | enahum <nahumhbl@gmail.com> | 2017-03-25 03:31:34 -0300 |
commit | 54d3d47daf9190275bbdaf8703b84969a4593451 (patch) | |
tree | 05899b296d0186c1a0da8a540bc486e34ad8eec9 /vendor/github.com/magiconair/properties/example_test.go | |
parent | 7460302dec7796e01c98264e84bece8169cb6ed9 (diff) | |
download | chat-54d3d47daf9190275bbdaf8703b84969a4593451.tar.gz chat-54d3d47daf9190275bbdaf8703b84969a4593451.tar.bz2 chat-54d3d47daf9190275bbdaf8703b84969a4593451.zip |
PLT-6076 Adding viper libs for config file changes (#5871)
* Adding viper libs for config file changes
* Removing the old fsnotify lib
* updating some missing libs
Diffstat (limited to 'vendor/github.com/magiconair/properties/example_test.go')
-rw-r--r-- | vendor/github.com/magiconair/properties/example_test.go | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/vendor/github.com/magiconair/properties/example_test.go b/vendor/github.com/magiconair/properties/example_test.go new file mode 100644 index 000000000..6f21dfbd8 --- /dev/null +++ b/vendor/github.com/magiconair/properties/example_test.go @@ -0,0 +1,93 @@ +// Copyright 2017 Frank Schroeder. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package properties + +import ( + "fmt" + "log" +) + +func ExampleLoad_iso88591() { + buf := []byte("key = ISO-8859-1 value with unicode literal \\u2318 and umlaut \xE4") // 0xE4 == ä + p, _ := Load(buf, ISO_8859_1) + v, ok := p.Get("key") + fmt.Println(ok) + fmt.Println(v) + // Output: + // true + // ISO-8859-1 value with unicode literal ⌘ and umlaut ä +} + +func ExampleLoad_utf8() { + p, _ := Load([]byte("key = UTF-8 value with unicode character ⌘ and umlaut ä"), UTF8) + v, ok := p.Get("key") + fmt.Println(ok) + fmt.Println(v) + // Output: + // true + // UTF-8 value with unicode character ⌘ and umlaut ä +} + +func ExampleProperties_GetBool() { + var input = ` + key=1 + key2=On + key3=YES + key4=true` + p, _ := Load([]byte(input), ISO_8859_1) + fmt.Println(p.GetBool("key", false)) + fmt.Println(p.GetBool("key2", false)) + fmt.Println(p.GetBool("key3", false)) + fmt.Println(p.GetBool("key4", false)) + fmt.Println(p.GetBool("keyX", false)) + // Output: + // true + // true + // true + // true + // false +} + +func ExampleProperties_GetString() { + p, _ := Load([]byte("key=value"), ISO_8859_1) + v := p.GetString("another key", "default value") + fmt.Println(v) + // Output: + // default value +} + +func Example() { + // Decode some key/value pairs with expressions + p, err := Load([]byte("key=value\nkey2=${key}"), ISO_8859_1) + if err != nil { + log.Fatal(err) + } + + // Get a valid key + if v, ok := p.Get("key"); ok { + fmt.Println(v) + } + + // Get an invalid key + if _, ok := p.Get("does not exist"); !ok { + fmt.Println("invalid key") + } + + // Get a key with a default value + v := p.GetString("does not exist", "some value") + fmt.Println(v) + + // Dump the expanded key/value pairs of the Properties + fmt.Println("Expanded key/value pairs") + fmt.Println(p) + + // Output: + // value + // invalid key + // some value + // Expanded key/value pairs + // key = value + // key2 = value +} |