41 lines
867 B
Go
41 lines
867 B
Go
package storage
|
|
|
|
import (
|
|
"git.insit.tech/sas/rtsp_proxy/proto/common"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
// CreateFileName creates FileName structure.
|
|
func CreateFileName(dirData string, resolutions []string, cutURI string, period int, number int) *common.FileName {
|
|
fn := common.FileName{
|
|
Path: dirData + "/" + cutURI + "/" + resolutions[0],
|
|
TimeNow: time.Now().Format("15-04-05_02-01-2006"),
|
|
Name: "videoFragment",
|
|
Number: number,
|
|
Duration: float64(period),
|
|
}
|
|
|
|
return &fn
|
|
}
|
|
|
|
// ReadDir reads directory and returns the slice of files in th directory.
|
|
func ReadDir(dirData string) ([]os.DirEntry, error) {
|
|
files, err := os.ReadDir(dirData)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return files, nil
|
|
}
|
|
|
|
// Exists check if the file or directory exists.
|
|
func Exists(file string) bool {
|
|
_, err := os.Stat(file)
|
|
if err == nil {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|