Skip to content

Commit

Permalink
增加单值解析
Browse files Browse the repository at this point in the history
  • Loading branch information
davyxu committed Jul 10, 2019
1 parent a644d24 commit 738a995
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions util/kvfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ func ReadKVFile(filename string, callback func(k, v string) bool) (ret error) {

// 等号切分KV
pairs := strings.Split(line, "=")
if len(pairs) == 2 {

switch len(pairs) {
case 1:
value := strings.TrimSpace(pairs[0])
return callback("", value)
case 2:
key := strings.TrimSpace(pairs[0])
value := strings.TrimSpace(pairs[1])

return callback(key, value)
default:
ret = errors.New("Require '=' splite key and value")
return false
}

ret = errors.New("Require '=' splite key and value")
return false
})

if readErr != nil {
Expand Down

0 comments on commit 738a995

Please sign in to comment.