...
1
2
3
4
5 package properties
6
7 import (
8 "fmt"
9 "log"
10 )
11
12 func ExampleLoad_iso88591() {
13 buf := []byte("key = ISO-8859-1 value with unicode literal \\u2318 and umlaut \xE4")
14 p, _ := Load(buf, ISO_8859_1)
15 v, ok := p.Get("key")
16 fmt.Println(ok)
17 fmt.Println(v)
18
19
20
21 }
22
23 func ExampleLoad_utf8() {
24 p, _ := Load([]byte("key = UTF-8 value with unicode character ⌘ and umlaut ä"), UTF8)
25 v, ok := p.Get("key")
26 fmt.Println(ok)
27 fmt.Println(v)
28
29
30
31 }
32
33 func ExampleProperties_GetBool() {
34 var input = `
35 key=1
36 key2=On
37 key3=YES
38 key4=true`
39 p, _ := Load([]byte(input), ISO_8859_1)
40 fmt.Println(p.GetBool("key", false))
41 fmt.Println(p.GetBool("key2", false))
42 fmt.Println(p.GetBool("key3", false))
43 fmt.Println(p.GetBool("key4", false))
44 fmt.Println(p.GetBool("keyX", false))
45
46
47
48
49
50
51 }
52
53 func ExampleProperties_GetString() {
54 p, _ := Load([]byte("key=value"), ISO_8859_1)
55 v := p.GetString("another key", "default value")
56 fmt.Println(v)
57
58
59 }
60
61 func Example() {
62
63 p, err := Load([]byte("key=value\nkey2=${key}"), ISO_8859_1)
64 if err != nil {
65 log.Fatal(err)
66 }
67
68
69 if v, ok := p.Get("key"); ok {
70 fmt.Println(v)
71 }
72
73
74 if _, ok := p.Get("does not exist"); !ok {
75 fmt.Println("invalid key")
76 }
77
78
79 v := p.GetString("does not exist", "some value")
80 fmt.Println(v)
81
82
83 fmt.Println("Expanded key/value pairs")
84 fmt.Println(p)
85
86
87
88
89
90
91
92
93 }
94
View as plain text