Created
February 8, 2018 18:51
-
-
Save nikos-glikis/7135dd9acd1b0ad24b65a67c60ac958a to your computer and use it in GitHub Desktop.
Append to file golang.
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 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