From 9268afb15d0893dbc48b06052b370d84c67144a1 Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Fri, 26 Jun 2015 16:05:09 +0200 Subject: [PATCH] Cosmetic changes --- gin.go | 34 +++++++++++++++--------------- routergroup.go | 56 ++++++++++++++++++++++++++------------------------ 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/gin.go b/gin.go index e505bb44..295e18f4 100644 --- a/gin.go +++ b/gin.go @@ -19,9 +19,24 @@ const Version = "v1.0rc2" var default404Body = []byte("404 page not found") var default405Body = []byte("405 method not allowed") +type HandlerFunc func(*Context) +type HandlersChain []HandlerFunc + +func (c HandlersChain) Last() HandlerFunc { + length := len(c) + if length > 0 { + return c[length-1] + } + return nil +} + type ( - HandlerFunc func(*Context) - HandlersChain []HandlerFunc + RoutesInfo []RouteInfo + RouteInfo struct { + Method string + Path string + Handler string + } // Represents the web framework, it wraps the blazing fast httprouter multiplexer and a list of global middlewares. Engine struct { @@ -61,25 +76,10 @@ type ( HandleMethodNotAllowed bool ForwardedByClientIP bool } - - RoutesInfo []RouteInfo - RouteInfo struct { - Method string - Path string - Handler string - } ) var _ RoutesInterface = &Engine{} -func (c HandlersChain) Last() HandlerFunc { - length := len(c) - if length > 0 { - return c[length-1] - } - return nil -} - // Returns a new blank Engine instance without any middleware attached. // The most basic configuration func New() *Engine { diff --git a/routergroup.go b/routergroup.go index 92c0a1f2..b77a55b7 100644 --- a/routergroup.go +++ b/routergroup.go @@ -11,37 +11,39 @@ import ( "strings" ) -type RoutesInterface interface { - routesInterface - Group(string, ...HandlerFunc) *RouterGroup -} +type ( + RoutesInterface interface { + routesInterface + Group(string, ...HandlerFunc) *RouterGroup + } -type routesInterface interface { - Use(...HandlerFunc) routesInterface + routesInterface interface { + Use(...HandlerFunc) routesInterface - Handle(string, string, ...HandlerFunc) routesInterface - Any(string, ...HandlerFunc) routesInterface - GET(string, ...HandlerFunc) routesInterface - POST(string, ...HandlerFunc) routesInterface - DELETE(string, ...HandlerFunc) routesInterface - PATCH(string, ...HandlerFunc) routesInterface - PUT(string, ...HandlerFunc) routesInterface - OPTIONS(string, ...HandlerFunc) routesInterface - HEAD(string, ...HandlerFunc) routesInterface + Handle(string, string, ...HandlerFunc) routesInterface + Any(string, ...HandlerFunc) routesInterface + GET(string, ...HandlerFunc) routesInterface + POST(string, ...HandlerFunc) routesInterface + DELETE(string, ...HandlerFunc) routesInterface + PATCH(string, ...HandlerFunc) routesInterface + PUT(string, ...HandlerFunc) routesInterface + OPTIONS(string, ...HandlerFunc) routesInterface + HEAD(string, ...HandlerFunc) routesInterface - StaticFile(string, string) routesInterface - Static(string, string) routesInterface - StaticFS(string, http.FileSystem) routesInterface -} + StaticFile(string, string) routesInterface + Static(string, string) routesInterface + StaticFS(string, http.FileSystem) routesInterface + } -// Used internally to configure router, a RouterGroup is associated with a prefix -// and an array of handlers (middlewares) -type RouterGroup struct { - Handlers HandlersChain - BasePath string - engine *Engine - root bool -} + // Used internally to configure router, a RouterGroup is associated with a prefix + // and an array of handlers (middlewares) + RouterGroup struct { + Handlers HandlersChain + BasePath string + engine *Engine + root bool + } +) var _ RoutesInterface = &RouterGroup{}