This commit is contained in:
hoteas 2018-11-15 03:44:50 +00:00
parent a5895af113
commit c90bb1cd84
2 changed files with 25 additions and 3 deletions

View File

@ -45,13 +45,25 @@ func (this *Application) Run(router Router) {
this.Router = router this.Router = router
//重新设置MethodRouter//直达路由 //重新设置MethodRouter//直达路由
this.MethodRouter=MethodRouter{} this.MethodRouter=MethodRouter{}
modeRouterStrict:=true
if this.Config.Get("modeRouterStrict").(bool)==false{
modeRouterStrict=false
}
if router!=nil{ if router!=nil{
for pk,pv:= range router{ for pk,pv:= range router{
if !modeRouterStrict{
pk=strings.ToLower(pk)
}
if pv!=nil{ if pv!=nil{
for ck,cv:=range pv{ for ck,cv:=range pv{
if !modeRouterStrict{
ck=strings.ToLower(ck)
}
if cv!=nil{ if cv!=nil{
for mk,mv:=range cv{ for mk,mv:=range cv{
if !modeRouterStrict{
mk=strings.ToLower(mk)
}
this.MethodRouter["/"+pk+"/"+ck+"/"+mk]=mv this.MethodRouter["/"+pk+"/"+ck+"/"+mk]=mv
} }
} }
@ -226,6 +238,8 @@ func (this *Application) urlSer(url string) (string, []string) {
} }
//访问 //访问
func (this *Application) handler(w http.ResponseWriter, req *http.Request) { func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
o, s := this.urlSer(req.RequestURI) o, s := this.urlSer(req.RequestURI)
@ -296,9 +310,16 @@ func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
// } // }
// //
//} //}
//验证接口严格模式
modeRouterStrict:=this.Config.Get("modeRouterStrict").(bool)
tempHandlerStr:=context.HandlerStr
if !modeRouterStrict{
tempHandlerStr=strings.ToLower(tempHandlerStr)
}
if this.MethodRouter[context.HandlerStr]!=nil{ //执行接口
this.MethodRouter[context.HandlerStr](&context) if this.MethodRouter[tempHandlerStr]!=nil{
this.MethodRouter[tempHandlerStr](&context)
context.View() context.View()
return return
} }

1
var.go
View File

@ -22,4 +22,5 @@ var Config = Map{
"sessionName": "HOTIME", "sessionName": "HOTIME",
"error": Map{}, "error": Map{},
"debug":1,//debug 0关闭1开启 "debug":1,//debug 0关闭1开启
"modeRouterStrict":false,//路由严格模式/a/b/c
} }