first commit
This commit is contained in:
34
pkg/tools/path.go
Normal file
34
pkg/tools/path.go
Normal file
@ -0,0 +1,34 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const (
|
||||
urlPre = "/api/v1/attachment"
|
||||
)
|
||||
|
||||
func Mkdir(basePath string, folderName string) string {
|
||||
folderPath := filepath.Join(basePath, folderName)
|
||||
_ = os.MkdirAll(folderPath, os.ModePerm)
|
||||
return folderPath
|
||||
}
|
||||
|
||||
func BasePath() string {
|
||||
return viper.GetString("attachment.path")
|
||||
}
|
||||
|
||||
func UrlBasePath() string {
|
||||
return "/static"
|
||||
}
|
||||
|
||||
func URLPath(filePath string) string {
|
||||
return filepath.Join("/", UrlBasePath(), filePath)
|
||||
}
|
||||
|
||||
func AttachmentUrl(relative string) string {
|
||||
return path.Join(urlPre, relative)
|
||||
}
|
||||
Reference in New Issue
Block a user