Files
dify-plugin-daemon/pkg/utils/tmpfile/tmpfile.go
2025-11-17 15:58:50 +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
}