插件增加静态文件目录自动映射,优化插件模板引擎与主模块的耦合关系

This commit is contained in:
孟帅
2023-06-14 18:09:49 +08:00
parent a232986311
commit 564107b980
29 changed files with 210 additions and 158 deletions

View File

@@ -11,16 +11,26 @@ import (
"hotgo/internal/consts"
)
func GetTag(name string) string {
return consts.AddonsTag + name
// GetModulePath 获取指定模块相对路径
func GetModulePath(name string) string {
return "./" + consts.AddonsDir + "/" + name
}
func Tpl(name, tpl string) string {
return consts.AddonsDir + "/" + name + "/" + tpl
// ViewPath 默认的插件模板路径
func ViewPath(name string) string {
return consts.AddonsDir + "/" + name + "/" + "resource/template"
}
// StaticPath 默认的插件静态路映射关系
// 最终效果:对外访问地址:/addons/插件模块名称;静态资源路径:/addons/插件模块名称/设置的子路径。
// 如果你不喜欢现在的路由风格,可以自行调整
func StaticPath(name, path string) (string, string) {
return "/" + consts.AddonsDir + "/" + name, consts.AddonsDir + "/" + name + "/" + path
}
// RouterPrefix 路由前缀
// 最终效果:/应用名称/插件模块名称/xxx/xxx。如果你不喜欢现在的路由风格,可以自行调整
// 最终效果:/应用名称/插件模块名称/xxx/xxx。
// 如果你不喜欢现在的路由风格,可以自行调整
func RouterPrefix(ctx context.Context, app, name string) string {
var prefix = "/"
if app != "" {