Files
servicebase/pkg/tools/path.go
2025-11-18 17:48:20 +08:00

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)
}