title: How to append to a file if it exists else create a new and write to it
body: <p>I have a file that I would like to add some contents to. I first check if that file exists. If it does, I add contents to it. If not, I just create a new file with that name and write to it. For this, I am doing something like:</p>
  
  <pre><code>if _, err := os.Stat(filename); os.IsNotExist(err) {
      f, err := os.Create(filename)
      if err != nil {
          panic(err)
      }
          ....
  } else {
      f, _ := os.OpenFile(filename, os.O_RDWR|os.O_APPEND, 0660);
      ....
  }
  </code></pre>
  
  <p>Is it possible to make this code shorter like 1-2 liner?</p>