Skip to content

Instantly share code, notes, and snippets.

@ivanzoid
Last active January 12, 2019 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivanzoid/54eecac527bb9b51d9a2c771a98af500 to your computer and use it in GitHub Desktop.
Save ivanzoid/54eecac527bb9b51d9a2c771a98af500 to your computer and use it in GitHub Desktop.
package main
import (
"os"
"bufio"
)
func readFirstLineFromFile(path string) (string, error) {
file, err := os.Open(path)
if err != nil {
return "", err
}
defer file.Close()
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
scanner.Scan()
return scanner.Text(), nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment