Ai
1 Star 2 Fork 0

Eolink/apinto-dashboard

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
module.go 851 Bytes
一键复制 编辑 原始数据 按行查看 历史
zeke 提交于 2022-04-24 12:22 +08:00 . json 编辑器及路由重新处理
package apinto_dashboard
import (
"net/http"
"strings"
)
type ViewLookup interface {
Lookup(r *http.Request) (view string, data interface{}, has bool)
}
type IModule interface {
http.Handler
ViewLookup
}
type ModuleViewFinder struct {
views map[string]string
prefix string
defaultName string
}
func NewViewModuleEmpty(prefix string, views map[string]string, defaultName string) *ModuleViewFinder {
prefix = strings.TrimSuffix(prefix, "/")
return &ModuleViewFinder{
views: views,
prefix: prefix,
defaultName: defaultName,
}
}
func (v *ModuleViewFinder) Lookup(r *http.Request) (view string, has bool) {
path := r.URL.Path
name := strings.TrimPrefix(path, v.prefix)
if name == "" || name == "/" {
name = v.defaultName
}
name = strings.TrimPrefix(name, "/")
vn, has := v.views[name]
return vn, has
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/eolink_admin/apinto-dashboard.git
git@gitee.com:eolink_admin/apinto-dashboard.git
eolink_admin
apinto-dashboard
apinto-dashboard
main

搜索帮助