1 package main 2 3 import "os" 4 5 // writeFile creates a file at the given filename and writes the provided bytes 6 // to it. Errors if the file already exists. 7 func writeFile(filename string, bytes []byte) error { 8 f, err := os.OpenFile(filename, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0644) 9 if err != nil { 10 return err 11 } 12 _, err = f.Write(bytes) 13 return err 14 } 15