code: func openFileWithFlags(fileName string, flags int) (*os.File, error) {
  	checkVersion := false
  
  	// Check if file already exists
  	if s, err := os.Stat(fileName); s != nil && err == nil {
  		checkVersion = true
  	}
  	file, err := os.OpenFile(fileName, flags, 0666)
  	if err != nil {
  		return nil, err
  	}
  
  	if checkVersion {
  		err = checkFileVersion(file)
  	} else {
  		// This is a new file, write our file version
  		err = util.WriteInt(file, fileVersion)
  	}
  	if err != nil {
  		file.Close()
  		file = nil
  	}
  	return file, err
  }
docs: // openFileWithModes opens the file specified by `filename`, using
  // the `modes` as open flags.
  // If the file exists, it checks that the version is supported.
  // If no open mode override is provided, the file is created if not present,
  // opened in Read/Write and Append mode.