1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-09 13:05:56 +00:00

formatting

Former-commit-id: 037081db5d6d4434e873ca8b75334ee43e046b6a
This commit is contained in:
Gerasimos (Makis) Maropoulos
2019-08-17 10:06:20 +03:00
parent 00967408dc
commit 07046ab978
112 changed files with 477 additions and 517 deletions

View File

@@ -17,22 +17,20 @@ import (
// to store the "offline" routes.
const MethodNone = "NONE"
var (
// AllMethods contains the valid http methods:
// "GET", "POST", "PUT", "DELETE", "CONNECT", "HEAD",
// "PATCH", "OPTIONS", "TRACE".
AllMethods = []string{
http.MethodGet,
http.MethodPost,
http.MethodPut,
http.MethodDelete,
http.MethodConnect,
http.MethodHead,
http.MethodPatch,
http.MethodOptions,
http.MethodTrace,
}
)
// AllMethods contains the valid http methods:
// "GET", "POST", "PUT", "DELETE", "CONNECT", "HEAD",
// "PATCH", "OPTIONS", "TRACE".
var AllMethods = []string{
http.MethodGet,
http.MethodPost,
http.MethodPut,
http.MethodDelete,
http.MethodConnect,
http.MethodHead,
http.MethodPatch,
http.MethodOptions,
http.MethodTrace,
}
// repository passed to all parties(subrouters), it's the object witch keeps
// all the routes.
@@ -403,7 +401,6 @@ func (api *APIBuilder) HandleMany(methodOrMulti string, relativePathorMulti stri
}
routes = append(routes, api.Handle(method, p, handlers...))
}
}
}
return
@@ -433,7 +430,6 @@ func (api *APIBuilder) HandleDir(requestPath, directory string, opts ...DirOptio
// and we need that path to call the `StripPrefix`.
if _, fullpath := splitSubdomainAndPath(joinPath(api.relativePath, requestPath)); fullpath != "/" {
h = StripPrefix(fullpath, h)
}
requestPath = joinPath(requestPath, WildcardFileParam())

View File

@@ -179,7 +179,6 @@ func (h *routerHandler) HandleRequest(ctx context.Context) {
method := ctx.Method()
path := ctx.Path()
if !ctx.Application().ConfigurationReadOnly().GetDisablePathCorrection() {
if len(path) > 1 && strings.HasSuffix(path, "/") {
// Remove trailing slash and client-permanent rule for redirection,
// if confgiuration allows that and path has an extra slash.

View File

@@ -581,7 +581,6 @@ func TypeByExtension(ext string) (typ string) {
// mime.TypeByExtension returns as text/plain; | charset=utf-8 the static .js (not always)
if ext == ".js" && (typ == "text/plain" || typ == "text/plain; charset=utf-8") {
if ext == ".js" {
typ = "application/javascript"
}

View File

@@ -9,26 +9,44 @@ func TestCleanPath(t *testing.T) {
path string
expected string
}{
{"/",
"/"},
{"noslashPrefix",
"/noslashPrefix"},
{"slashSuffix/",
"/slashSuffix"},
{"noSlashPrefixAndslashSuffix/",
"/noSlashPrefixAndslashSuffix"},
{
"/",
"/",
},
{
"noslashPrefix",
"/noslashPrefix",
},
{
"slashSuffix/",
"/slashSuffix",
},
{
"noSlashPrefixAndslashSuffix/",
"/noSlashPrefixAndslashSuffix",
},
// don't do any clean up inside {},
// fixes #927.
{"/total/{year:string regexp(\\d{4})}",
"/total/{year:string regexp(\\d{4})}"},
{"/total/{year:string regexp(\\d{4})}/more",
"/total/{year:string regexp(\\d{4})}/more"},
{"/total/{year:string regexp(\\d{4})}/more/{s:string regexp(\\d{7})}",
"/total/{year:string regexp(\\d{4})}/more/{s:string regexp(\\d{7})}"},
{"/single_no_params",
"/single_no_params"},
{"/single/{id:uint64}",
"/single/{id:uint64}"},
{
"/total/{year:string regexp(\\d{4})}",
"/total/{year:string regexp(\\d{4})}",
},
{
"/total/{year:string regexp(\\d{4})}/more",
"/total/{year:string regexp(\\d{4})}/more",
},
{
"/total/{year:string regexp(\\d{4})}/more/{s:string regexp(\\d{7})}",
"/total/{year:string regexp(\\d{4})}/more/{s:string regexp(\\d{7})}",
},
{
"/single_no_params",
"/single_no_params",
},
{
"/single/{id:uint64}",
"/single/{id:uint64}",
},
}
for i, tt := range tests {
@@ -43,18 +61,30 @@ func TestSplitPath(t *testing.T) {
path string
expected []string
}{
{"/v2/stores/{id:string format(uuid)} /v3",
[]string{"/v2/stores/{id:string format(uuid)}", "/v3"}},
{"/user/{id:uint64} /admin/{id:uint64}",
[]string{"/user/{id:uint64}", "/admin/{id:uint64}"}},
{"/users/{id:int} /admins/{id:int64}",
[]string{"/users/{id:int}", "/admins/{id:int64}"}},
{"/user /admin",
[]string{"/user", "/admin"}},
{"/single_no_params",
[]string{"/single_no_params"}},
{"/single/{id:int}",
[]string{"/single/{id:int}"}},
{
"/v2/stores/{id:string format(uuid)} /v3",
[]string{"/v2/stores/{id:string format(uuid)}", "/v3"},
},
{
"/user/{id:uint64} /admin/{id:uint64}",
[]string{"/user/{id:uint64}", "/admin/{id:uint64}"},
},
{
"/users/{id:int} /admins/{id:int64}",
[]string{"/users/{id:int}", "/admins/{id:int64}"},
},
{
"/user /admin",
[]string{"/user", "/admin"},
},
{
"/single_no_params",
[]string{"/single_no_params"},
},
{
"/single/{id:int}",
[]string{"/single/{id:int}"},
},
}
equalSlice := func(s1 []string, s2 []string) bool {
@@ -78,6 +108,7 @@ func TestSplitPath(t *testing.T) {
}
}
}
func TestSplitSubdomainAndPath(t *testing.T) {
tests := []struct {
original string

View File

@@ -51,7 +51,6 @@ type Route struct {
// handlers are being changed to validate the macros at serve time, if needed.
func NewRoute(method, subdomain, unparsedPath, mainHandlerName string,
handlers context.Handlers, macros macro.Macros) (*Route, error) {
tmpl, err := macro.Parse(unparsedPath, macros)
if err != nil {
return nil, err

View File

@@ -3,13 +3,13 @@
package router
import (
"github.com/kataras/iris/macro"
"testing"
"github.com/kataras/iris/macro"
)
func TestRouteStaticPath(t *testing.T) {
var tests = []struct {
tests := []struct {
tmpl string
static string
}{

View File

@@ -42,7 +42,6 @@ func (router *Router) RefreshRouter() error {
//
// Use of RefreshRouter to re-build the router if needed.
func (router *Router) BuildRouter(cPool *context.Pool, requestHandler RequestHandler, routesProvider RoutesProvider, force bool) error {
if requestHandler == nil {
return errors.New("router: request handler is nil")
}

View File

@@ -76,6 +76,7 @@ func TestMiddlewareByRouteDef(t *testing.T) {
testResponse(t, app, "/mypath")
}
func TestMiddlewareByUseAndDoneDef(t *testing.T) {
app := iris.New()
app.Use(firstUseGlobalHandler, secondUseGlobalHandler, firstUseHandler, secondUseHandler)

View File

@@ -52,7 +52,7 @@ func h3(ctx context.Context) {
}
func TestRouterWildcardDifferentPrefixPath(t *testing.T) {
var tt = []testRoute{
tt := []testRoute{
{"GET", "/s/{p:path}", h, []testRouteRequest{
{"GET", "", "/s/that/is/wildcard", iris.StatusOK, same_as_request_path},
{"GET", "", "/s/ok", iris.StatusOK, same_as_request_path},
@@ -71,7 +71,7 @@ func TestRouterWildcardDifferentPrefixPath(t *testing.T) {
}
func TestRouterWildcardAndStatic(t *testing.T) {
var tt = []testRoute{
tt := []testRoute{
{"GET", "/some/{p:path}", h2, []testRouteRequest{
{"GET", "", "/some/that/is/wildcard", iris.StatusForbidden, same_as_request_path},
{"GET", "", "/some/did", iris.StatusForbidden, same_as_request_path},
@@ -95,7 +95,7 @@ func TestRouterWildcardAndStatic(t *testing.T) {
}
func TestRouterWildcardRootMany(t *testing.T) {
var tt = []testRoute{
tt := []testRoute{
// all routes will be handlded by "h" because we added wildcard to root,
// this feature is very important and can remove noumerous of previous hacks on our apps.
{"GET", "/{p:path}", h, []testRouteRequest{
@@ -121,7 +121,7 @@ func TestRouterWildcardRootMany(t *testing.T) {
}
func TestRouterWildcardRootManyAndRootStatic(t *testing.T) {
var tt = []testRoute{
tt := []testRoute{
// routes that may return 404 will be handled by the below route ("h" handler) because we added wildcard to root,
// this feature is very important and can remove noumerous of previous hacks on our apps.
//

View File

@@ -88,7 +88,8 @@ func defaultErrorCodeHandlers() *ErrorCodeHandlers {
for _, statusCode := range []int{
http.StatusNotFound,
http.StatusMethodNotAllowed,
http.StatusInternalServerError} {
http.StatusInternalServerError,
} {
chs.Register(statusCode, statusText(statusCode))
}

View File

@@ -61,7 +61,6 @@ func TestOnAnyErrorCode(t *testing.T) {
Body().Equal(http.StatusText(iris.StatusNotAcceptable))
checkAndClearBuf(t, buff, expectedPrintBeforeExecuteErr)
}
func checkAndClearBuf(t *testing.T, buff *bytes.Buffer, expected string) {