From c90bb1cd84545271705d0e3934ddea572ec88b8e Mon Sep 17 00:00:00 2001 From: hoteas Date: Thu, 15 Nov 2018 03:44:50 +0000 Subject: [PATCH] --- application.go | 27 ++++++++++++++++++++++++--- var.go | 1 + 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/application.go b/application.go index 8dcd786..62feea7 100644 --- a/application.go +++ b/application.go @@ -45,13 +45,25 @@ func (this *Application) Run(router Router) { this.Router = router //重新设置MethodRouter//直达路由 this.MethodRouter=MethodRouter{} - + modeRouterStrict:=true + if this.Config.Get("modeRouterStrict").(bool)==false{ + modeRouterStrict=false + } if router!=nil{ for pk,pv:= range router{ + if !modeRouterStrict{ + pk=strings.ToLower(pk) + } if pv!=nil{ for ck,cv:=range pv{ + if !modeRouterStrict{ + ck=strings.ToLower(ck) + } if cv!=nil{ for mk,mv:=range cv{ + if !modeRouterStrict{ + mk=strings.ToLower(mk) + } 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) { 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() return } diff --git a/var.go b/var.go index 91dc555..9a1df9b 100644 --- a/var.go +++ b/var.go @@ -22,4 +22,5 @@ var Config = Map{ "sessionName": "HOTIME", "error": Map{}, "debug":1,//debug 0关闭1开启 + "modeRouterStrict":false,//路由严格模式/a/b/c }