I want to read a file from S3. This file contains several lines, and In each line, there is a string.
something like:
Alice
Bob
Jack
I have an API that reads my file, but the output is: []byte
How can I split the byte array by a new line and convert them to string? My Desire output is an array of strings.
CodePudding user response:
To create a slice of strings from a slice of bytes, convert the slice of bytes to a string and split the string on newline:
lines := strings.Split(string(fileContents), "\n")