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
ini文件:
```
[server]
#local server ip and port
#192.168.10.2,
ip=
port=8080
```
怎么做到输出之后是:
```
server,ip
server,port=8080
```
这种形式,是需要拼接字符串么,具体怎么写
#12
更多评论