I am learning Go these days and I am trying to read a file which includes a list of URLs so that I can send a simple GET request to them. So, I need to read the list and then add its line of the list as an element in a slice. However, I am getting a weird output. Below are my code and the .txt file.
code:
func openFile() {
urls := make([]string, 3)
for _, filename := range os.Args[1:] {
urlsBytes, err := ioutil.ReadFile(filename)
if err != nil {
fmt.Println(err)
}
for _, line := range strings.Split(string(urlsBytes), "\n") {
urls = append(urls, line)
}
}
fmt.Println(urls)
}
file:
https://www.youtube.com/
https://www.facebook.com/
https://aws.amazon.com/
output:
go run Main.go test2.txt
https://aws.amazon.com/]/m/