Skip to content

Instantly share code, notes, and snippets.

@nikos-glikis
Created February 8, 2018 18:51
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 nikos-glikis/7135dd9acd1b0ad24b65a67c60ac958a to your computer and use it in GitHub Desktop.
Save nikos-glikis/7135dd9acd1b0ad24b65a67c60ac958a to your computer and use it in GitHub Desktop.
Append to file golang.
func addToLog(text string, logfile string) {
f, err := os.OpenFile(logfile, os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
panic(err)
}
defer f.Close()
if _, err = f.WriteString(text); err != nil {
panic(err)
}
if _, err = f.WriteString("\n"); err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment