-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.go
36 lines (30 loc) · 906 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package cos
import (
"fmt"
"path"
"strings"
"github.com/goravel/framework/contracts/filesystem"
"github.com/goravel/framework/support/file"
)
func fullPathOfFile(filePath string, source filesystem.File, name string) (string, error) {
extension := path.Ext(name)
if extension == "" {
var err error
extension, err = file.Extension(source.File(), true)
if err != nil {
return "", err
}
return fmt.Sprintf("%s/%s.%s", filePath, strings.TrimSuffix(strings.TrimPrefix(path.Base(name), "/"), "/"), extension), nil
} else {
return fmt.Sprintf("%s/%s", filePath, strings.TrimPrefix(path.Base(name), "/")), nil
}
}
func validPath(path string) string {
realPath := strings.TrimPrefix(path, "./")
realPath = strings.TrimPrefix(realPath, "/")
realPath = strings.TrimPrefix(realPath, ".")
if realPath != "" && !strings.HasSuffix(realPath, "/") {
realPath += "/"
}
return realPath
}