-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_properties_test.go
96 lines (83 loc) · 2.1 KB
/
example_properties_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package properties_test
import (
"fmt"
"log"
"github.com/obity/properties"
)
func Example() {
p := properties.NewProperties()
p.SetProperty("HttpPort", "8081")
p.SetProperty("MongoServer", "mongodb://10.11.1.5,10.11.1.6,10.11.1.7/?replicaSet=mytest")
p.SetPropertySlice("LogLevel", "Debug", "Info", "Warn")
err := p.StoreToFile("config.properties")
if err != nil {
log.Println(err)
return
}
// Output:
//// config.properties
// HttpPort = 8081
// MongoServer = mongodb://10.11.1.5,10.11.1.6,10.11.1.7/?replicaSet=mytest
// LogLevel = Debug,Info,Warn
}
func ExampleProperties_LoadFromFile() {
file := "./config.properties"
p := properties.NewProperties()
err := p.LoadFromFile(file)
if err != nil {
log.Println(err)
return
}
httpPort, isExist := p.Property("HttpPort")
if !isExist {
log.Println("HttpPort not exist")
}
fmt.Println(httpPort)
loglevel, isExist := p.PropertySlice("LogLevel")
if !isExist {
log.Println("LogLevel not exist")
}
fmt.Println(loglevel)
// Output:
// 8081
// [Debug Info Warn]
}
func ExampleProperties_PropertySlice() {
p := properties.NewProperties()
err := p.StoreToFile("webconfig.properties")
if err != nil {
log.Println(err)
return
}
loglevel, isExist := p.PropertySlice("LogLevel")
if !isExist {
log.Println("LogLevel not exist")
}
fmt.Println(loglevel)
// Output:
// [Debug Info Warn]
}
func ExampleProperties_SetProperty() {
p := properties.NewProperties()
p.SetProperty("HttpPort", "8081")
}
func ExampleProperties_SetPropertySlice() {
p := properties.NewProperties()
p.SetPropertySlice("LogLevel", "Debug", "Info", "Warn")
}
func ExampleProperties_StoreToFile() {
p := properties.NewProperties()
p.SetProperty("HttpPort", "8081")
p.SetProperty("MongoServer", "mongodb://10.11.1.5,10.11.1.6,10.11.1.7/?replicaSet=mytest")
p.SetPropertySlice("LogLevel", "Debug", "Info", "Warn")
err := p.StoreToFile("webconfig.properties")
if err != nil {
log.Println(err)
return
}
// Output:
//// webconfig.properties
// HttpPort = 8081
// MongoServer = mongodb://10.11.1.5,10.11.1.6,10.11.1.7/?replicaSet=mytest
// LogLevel = Debug,Info,Warn
}