tmpfile.go 383 B

1234567891011121314
  1. package tmpfile
  2. import "os"
  3. // CreateTempFile creates a temp file with the given prefix
  4. // and returns the path to the temp file and a function to clean up the temp file
  5. func CreateTempFile(prefix string) (*os.File, func(), error) {
  6. file, err := os.CreateTemp(os.TempDir(), prefix)
  7. if err != nil {
  8. return nil, nil, err
  9. }
  10. return file, func() { os.Remove(file.Name()) }, nil
  11. }