The following snippet shows how to print the content of a slice of strings into a file, separating each string with a new line.

package main

func main() {
    var text []string

    //... fill text with string values

    // writes a slice of strings to a file, one per line
    sep := "\n"
    for _, line := range text {
        if _, err = f.WriteString(line + sep); err != nil {

Pssst! Also check my latest YouTube video

I am writing a book on how to create a successful blog as a developer.
It will be released late February.
Signup to my newsletter to get 2/3 free chapters in your inbox in the next few weeks!