Files
2024-08-14 23:32:46 +08:00

14 lines
383 B
Go

package tmpfile
import "os"
// CreateTempFile creates a temp file with the given prefix
// and returns the path to the temp file and a function to clean up the temp file
func CreateTempFile(prefix string) (*os.File, func(), error) {
file, err := os.CreateTemp(os.TempDir(), prefix)
if err != nil {
return nil, nil, err
}
return file, func() { os.Remove(file.Name()) }, nil
}