Skip to content

Instantly share code, notes, and snippets.

@tsonglew
Created September 27, 2017 12:52
Show Gist options
  • Save tsonglew/9702255015e14df1d8f95a852a0ce0c8 to your computer and use it in GitHub Desktop.
Save tsonglew/9702255015e14df1d8f95a852a0ce0c8 to your computer and use it in GitHub Desktop.
read from file
func Content(filename string) (string, error) {
f, err = os.Open(filename)
if err != nil {
return nil, err
}
defer f.Close()
var result []byte
buf := make([]byte, 100)
for {
n, err := f.Read(buf[0:])
result = append(result, buf[0:n]...)
if err != nil {
if err == io.EOF {
break
}
return nil, err
}
}
return string(result), nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment