Files
projet_gestion_commande/backend/gestion/utils/utils.go
T

33 lines
781 B
Go

package utils
import (
"fmt"
"gestion/db"
"gestion/models"
"math/rand"
"os"
"path/filepath"
)
// --------------------------------------------
// MEDIA
// --------------------------------------------
func GetMediaForProduct(productID int) ([]models.Media, error) {
return db.DB.GetMediaByProductID(productID)
}
// --------------------------------------------
// FILES NAMES
// --------------------------------------------
func GenerateUniqueFileName(productName string, originalFileName string) string {
randomString := fmt.Sprintf("%d", rand.Intn(1000000))
ext := filepath.Ext(originalFileName)
return fmt.Sprintf("%s_%s%s", productName, randomString, ext)
}
func DeleteOldFile(filePath string) error {
return os.Remove(filePath)
}