Create a gist now

Instantly share code, notes, and snippets.

package main
import (
"bufio"
"fmt"
"log"
"os"
)
func readLines(path string) ([]string, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
var lines []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
return lines, scanner.Err()
}
func main() {
values, err := readLines("---yourfilepath---")
if err != nil {
log.Fatalf("readLines: %s", err)
}
fmt.Println(values)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment