3 ms·
OK, it looks like you simply copied the import block from the first StackOverflow result for "golang read file" (the giveaway is that the order of imports is in
by ominous_prime 13y ago
OK, it looks like you simply copied the import block from the first StackOverflow result for "golang read file" (the giveaway is that the order of imports is in the same non-formatted order as the top answer). That question, and its answer are covering more than simply reading in a file into a buffer.
The minimum is "os" and "io/ioutil"
f, _ := os.Open("/etc/ttys")
buff, _ := ioutil.ReadAll(f)
Edit: and as @exch pointed out, I forgot there's an ioutil.ReadFile helper too of you don't actually need access to the file object again.
- jabiko 13y agoThe parent comment has been removed but I think it's fair to add the missing context: http://i.imgur.com/xx7WLkx.png http://i.imgur.com/xx7WLkx.png