From 40cb8e0cf14546c20418a65b2a1a290ac22229d0 Mon Sep 17 00:00:00 2001 From: JessonChan Date: Fri, 18 Sep 2015 18:18:12 +0800 Subject: [PATCH] use reflect to ensure all methods been except --- router.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/router.go b/router.go index efb1a1f3..57addd4e 100644 --- a/router.go +++ b/router.go @@ -63,13 +63,14 @@ var ( "CONNECT": "CONNECT", } // these beego.Controller's methods shouldn't reflect to AutoRouter - exceptMethod = []string{"Init", "Prepare", "Finish", "Render", "RenderString", - "RenderBytes", "Redirect", "Abort", "StopRun", "UrlFor", "ServeJson", "ServeJsonp", - "ServeXml", "Input", "ParseForm", "GetString", "GetStrings", "GetInt", "GetBool", - "GetFloat", "GetFile", "SaveToFile", "StartSession", "SetSession", "GetSession", - "DelSession", "SessionRegenerateID", "DestroySession", "IsAjax", "GetSecureCookie", - "SetSecureCookie", "XsrfToken", "CheckXsrfCookie", "XsrfFormHtml", - "GetControllerAndAction"} + exceptMethod = func() []string { + methods := []string{} + rv := reflect.TypeOf(&Controller{}) + for i := 0; i < rv.NumMethod(); i++ { + methods = append(methods, rv.Method(i).Name) + } + return methods + }() urlPlaceholder = "{{placeholder}}" // DefaultAccessLogFilter will skip the accesslog if return true