I have a file like this: Each line represents a Website
1 www.google.com$
2 www.apple.com$
3 www.facebook.com$
I read it in golang like this:
type ListConf struct {
File string
Datas map[string]struct{}
}
func loadListConf(conf *ListConf, path string) {
file, err := os.Open(path + "/" + conf.File)
if err != nil {
fmt.Println("Load conf " + conf.File + " error: " + err.Error())
return
}
defer file.Close()
conf.Datas = make(map[string]struct{})
buf := bufio.NewReader(file)
end := false
for !end {
line, err := buf.ReadString('
')
if err != nil {
if err != io.EOF {
fmt.Println("Load conf " + conf.File + " error: " + err.Error())
return
} else {
end = true
}
}
item := strings.Trim(line, "
")
if item == "" {
continue
}
conf.Datas[item] = struct{}{}
}
}
But when I search key such like "www.google.com" in the map, it shows that there is not a "www.google.com" in the map.
website := "www.google.com"
if _, ok := conf.Datas[website]; ok {
fmt.Printf("%s is in the map.", website)
} else {
fmt.Printf("%s is not in the map.", website)
}
It print "www.google.com is not in the map". I found that a ^M in the end of each key in the map, my question is how can I remove the ^M character?
www.google.com^M
www.apple.com^M
www.facebook.com^M