35 lines
594 B
Go
35 lines
594 B
Go
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)
|
|
}
|