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
更多评论