whatsapp-multi-devicewhatsapp-apiwhatsapprestgolanggobotwhatsapp-web-multi-devicewhatsapp-api-gorest-apigolang-whatsapp-apigolang-whatsapp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
908 B
48 lines
908 B
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
)
|
|
|
|
// RemoveFile is removing file with delay
|
|
func RemoveFile(delaySecond int, paths ...string) error {
|
|
if delaySecond > 0 {
|
|
time.Sleep(time.Duration(delaySecond) * time.Second)
|
|
}
|
|
|
|
for _, path := range paths {
|
|
if path != "" {
|
|
err := os.Remove(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// CreateFolder create new folder and sub folder if not exist
|
|
func CreateFolder(folderPath ...string) error {
|
|
for _, folder := range folderPath {
|
|
newFolder := filepath.Join(".", folder)
|
|
err := os.MkdirAll(newFolder, os.ModePerm)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// PanicIfNeeded is panic if error is not nil
|
|
func PanicIfNeeded(err any, message ...string) {
|
|
if err != nil {
|
|
if fmt.Sprintf("%s", err) == "record not found" && len(message) > 0 {
|
|
panic(message[0])
|
|
} else {
|
|
panic(err)
|
|
}
|
|
}
|
|
}
|