Skip to content

Instantly share code, notes, and snippets.

@alidevhere
Created August 12, 2022 07:29
Show Gist options
  • Save alidevhere/00f9d1ebc6fbe61f6bc2736f9a2ea6c8 to your computer and use it in GitHub Desktop.
Save alidevhere/00f9d1ebc6fbe61f6bc2736f9a2ea6c8 to your computer and use it in GitHub Desktop.

Append to file in go

f, err := os.OpenFile("text.log",
	os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
	log.Println(err)
}
defer f.Close()
if _, err := f.WriteString("text to append\n"); err != nil {
	log.Println(err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment