Created
September 15, 2019 14:43
-
-
Save hitechqb/7c802e45144c2311e3858a2eafadf583 to your computer and use it in GitHub Desktop.
Using a Filename as an Input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func count(filename string) (int, error) { | |
file, err := os.Open(filename) | |
if err != nil { | |
return 0, errors.Wrapf(err, "unable to open %s", filename) | |
} | |
defer file.Close() | |
scanner := bufio.NewScanner(file) | |
count := 0 | |
for scanner.Scan() { | |
if scanner.Text() == "" { | |
count++ | |
} | |
} | |
return count, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment