Skip to content

Commit 0adfe12

Browse files
author
wander
committed
fixbug #1
#1
1 parent e75bcee commit 0adfe12

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

example/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import (
88
)
99

1010
func main() {
11-
// store to file
11+
var err error
12+
// store to file
1213
p := properties.NewProperties()
1314
p.SetProperty("HttpPort", "8081")
1415
p.SetProperty("MongoServer", "mongodb://10.11.1.5,10.11.1.6,10.11.1.7/?replicaSet=mytest")
1516
p.SetPropertySlice("LogLevel", "Debug", "Info", "Warn")
16-
err := p.StoreToFile("config.properties")
17+
err = p.StoreToFile("config.properties")
1718
if err != nil {
1819
log.Println(err)
1920
return

properties.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ func (p *Properties) line(key, value string, buf *bytes.Buffer) {
133133

134134
func (p *Properties) parseLine(line []byte) {
135135
lineStr := strings.TrimSpace(string(line))
136+
if isCommentline(lineStr) {
137+
return
138+
}
136139
splitStrs := strings.Split(lineStr, "=")
137140
key := strings.TrimSpace(splitStrs[0])
138141
value := strings.TrimSpace(splitStrs[1])
@@ -149,3 +152,14 @@ func (p *Properties) PropertyNames() []string {
149152
}
150153
return names
151154
}
155+
156+
// 过滤注释的行
157+
func isCommentline(line string) bool {
158+
if len(line) == 0 {
159+
return true
160+
}
161+
if strings.HasPrefix(line, "#") || strings.HasPrefix(line, "//") || strings.HasPrefix(line, "/*") {
162+
return true
163+
}
164+
return false
165+
}

0 commit comments

Comments
 (0)