per = make(map[string]interface{})
f, _ := os.Open("D:\\GoPoject\\initype\\src\\ini\\gconfig.ini")
buf := bufio.NewReader(f)
for {
l, err := buf.ReadString('\n')
line := strings.TrimSpace(l)
if err != nil {
if err != io.EOF {
}
if len(line) == 0 {
break
}
}
switch {
case len(line) == 0:
case line[0] == '[' && line[len(line)-1] == ']':
section := strings.TrimSpace(line[1 : len(line)-1])
fmt.Println(section)
default:
i := strings.IndexAny(line, "=")
per[strings.TrimSpace(line[0:i])] = strings.TrimSpace(line[i+1:])
}
}
for k, v := range per {
fmt.Println(k, v)
}
报错panic: runtime error: slice bounds out of range
![QQ截图20170626133936.jpg](http://studygolang.qiniudn.com/170626/95a3ae954a19522ce584982c1e44ed63.jpg)
#6
更多评论