Skip to content

Commit

Permalink
Modified # for config value that inside a line, only regard # as comm…
Browse files Browse the repository at this point in the history
…ent at the beginning. (#78)

* Modified # for config value that inside a line, only regard # as comment at the beginning. (ps: golint tars/util/conf/conf.go)

* Fixed a word
  • Loading branch information
jchalex authored and sandyskies committed Nov 27, 2018
1 parent d103d5e commit 1f986f8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tars/util/conf/conf.go
Expand Up @@ -99,7 +99,7 @@ func (e *elem) analysisPath(path string) []string {
return ret
}

//路径类似于/A/B/C或/A/B/C/
// path like /A/B/C or /A/B/C/
func (e *elem) getDomain(path string) ([]string, error) {
pathVec := e.analysisPath(path)
var domain []string
Expand Down Expand Up @@ -130,7 +130,7 @@ func (e *elem) getMap(path string) (map[string]string, error) {
return kvMap, nil
}

//路径类似于/A/B/C/<data>/A/B/C<data>
// path like /A/B/C/<data> or /A/B/C<data>
func (e *elem) getValue(path string) (string, error) {
pathVec := e.analysisPath(path)
targetNode, err := e.getElem(pathVec)
Expand Down Expand Up @@ -165,7 +165,7 @@ func NewConf(fileName string) (*Conf, error) {
func (c *Conf) InitFromFile(fileName string) error {
content, err := ioutil.ReadFile(fileName)
if err != nil {
return fmt.Errorf("read file %s rrror:%v", fileName, err)
return fmt.Errorf("read file %s error:%v", fileName, err)
}
return c.InitFromBytes(content)
}
Expand Down Expand Up @@ -195,7 +195,9 @@ func (c *Conf) InitFromBytes(content []byte) error {
lineDecoder.Split(bufio.ScanLines)
for lineDecoder.Scan() {
line := strings.Trim(lineDecoder.Text(), whiteSpaceChars)
line = strings.SplitN(line, "#", 2)[0]
if len(line) > 0 && line[0] == '#' {
continue
}
kv := strings.SplitN(line, "=", 2)
if len(kv) != 2 {
continue
Expand Down

0 comments on commit 1f986f8

Please sign in to comment.