diff --git a/core/host/proxy.go b/core/host/proxy.go index 5cb7cc4c..0714f4fb 100644 --- a/core/host/proxy.go +++ b/core/host/proxy.go @@ -43,7 +43,6 @@ func ProxyHandler(target *url.URL, config *tls.Config) *httputil.ReverseProxy { return p } - // mergeQuery return a query string that combines targetQuery and reqQuery // and remove the duplicated query parameters of them. func mergeQuery(targetQuery, reqQuery string) string { diff --git a/core/host/proxy_test.go b/core/host/proxy_test.go index 08f019ba..96070219 100644 --- a/core/host/proxy_test.go +++ b/core/host/proxy_test.go @@ -27,7 +27,7 @@ func TestProxy(t *testing.T) { config := &tls.Config{ InsecureSkipVerify: true, - MaxVersion: tls.VersionTLS12, + MaxVersion: tls.VersionTLS12, } proxy := host.NewProxy("", u, config) diff --git a/mvc/controller.go b/mvc/controller.go index 44ce0c9e..cedbfca0 100644 --- a/mvc/controller.go +++ b/mvc/controller.go @@ -318,7 +318,7 @@ func (c *ControllerActivator) parseMethods() { } func (c *ControllerActivator) parseMethod(m reflect.Method) { - httpMethod, httpPath, err := parseMethod(c.app.Router.Macros(), m, c.isReservedMethod,c.app.customPathWordFunc) + httpMethod, httpPath, err := parseMethod(c.app.Router.Macros(), m, c.isReservedMethod, c.app.customPathWordFunc) if err != nil { if err != errSkip { c.logErrorf("MVC: fail to parse the route path and HTTP method for '%s.%s': %v", c.fullName, m.Name, err) diff --git a/mvc/controller_method_parser.go b/mvc/controller_method_parser.go index 57a3b8bd..24e92726 100644 --- a/mvc/controller_method_parser.go +++ b/mvc/controller_method_parser.go @@ -92,21 +92,21 @@ func genParamKey(argIdx int) string { } type methodParser struct { - lexer *methodLexer - fn reflect.Method - macros *macro.Macros + lexer *methodLexer + fn reflect.Method + macros *macro.Macros customPathWordFunc CustomPathWordFunc } -func parseMethod(macros *macro.Macros, fn reflect.Method, skipper func(string) bool,wordFunc CustomPathWordFunc) (method, path string, err error) { +func parseMethod(macros *macro.Macros, fn reflect.Method, skipper func(string) bool, wordFunc CustomPathWordFunc) (method, path string, err error) { if skipper(fn.Name) { return "", "", errSkip } p := &methodParser{ - fn: fn, - lexer: newMethodLexer(fn.Name), - macros: macros, + fn: fn, + lexer: newMethodLexer(fn.Name), + macros: macros, customPathWordFunc: wordFunc, } return p.parse() @@ -121,7 +121,10 @@ var errSkip = errors.New("skip") var allMethods = append(router.AllMethods[0:], []string{"ALL", "ANY"}...) -type CustomPathWordFunc func(path, w string,wordIndex int) string +// CustomPathWordFunc describes the function which can be passed +// through `Application.SetCustomPathWordFunc` to customize +// the controllers method parsing. +type CustomPathWordFunc func(path, w string, wordIndex int) string func addPathWord(path, w string) string { if path[len(path)-1] != '/' { @@ -151,7 +154,7 @@ func (p *methodParser) parse() (method, path string, err error) { return "", "", errSkip } - wordIndex:=0 + wordIndex := 0 for { w := p.lexer.next() if w == "" { @@ -178,9 +181,9 @@ func (p *methodParser) parse() (method, path string, err error) { } // custom static path. - if p.customPathWordFunc!=nil { - path = p.customPathWordFunc(path, w,wordIndex) - }else{ + if p.customPathWordFunc != nil { + path = p.customPathWordFunc(path, w, wordIndex) + } else { // default static path. path = addPathWord(path, w) } diff --git a/mvc/mvc.go b/mvc/mvc.go index 6f0c8ad5..7b07731d 100644 --- a/mvc/mvc.go +++ b/mvc/mvc.go @@ -122,6 +122,8 @@ func (app *Application) SetName(appName string) *Application { return app } +// SetCustomPathWordFunc sets a custom function +// which is responsible to override the existing controllers method parsing. func (app *Application) SetCustomPathWordFunc(wordFunc CustomPathWordFunc) *Application { app.customPathWordFunc = wordFunc return app