1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-24 12:25:57 +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

@@ -8,10 +8,8 @@ import (
"github.com/iris-contrib/go.uuid"
)
var (
// Prefix the error prefix, applies to each error's message.
Prefix = ""
)
// Prefix the error prefix, applies to each error's message.
var Prefix = ""
// Error holds the error message, this message never really changes
type Error struct {

View File

@@ -14,7 +14,6 @@ var userMail = "user1@mail.go"
var expectedUserAlreadyExists = "User with mail: user1@mail.go already exists"
func ExampleError() {
fmt.Print(errUserAlreadyExists.Format(userMail).Append("Please change your mail addr"))
// Output:
@@ -38,7 +37,6 @@ func TestFormat(t *testing.T) {
}
func TestAppendErr(t *testing.T) {
errChangeMailMsg := "Please change your mail addr"
errChangeMail := fmt.Errorf(errChangeMailMsg) // test go standard error
errAppended := errUserAlreadyExists.AppendErr(errChangeMail)

View File

@@ -78,7 +78,6 @@ func (r *Reporter) AddErr(err error) bool {
//
// Returns true if this "err" is not nil and it's added to the reporter's stack.
func (r *Reporter) Add(format string, a ...interface{}) bool {
if format == "" && len(a) == 0 {
return false
}

View File

@@ -26,7 +26,7 @@ func FromStd(handler interface{}) context.Handler {
case context.Handler:
{
//
//it's already a iris handler
// it's already a iris handler
//
return handler.(context.Handler)
}
@@ -67,7 +67,6 @@ func FromStd(handler interface{}) context.Handler {
}
}
}
// FromStdWithNext receives a standar handler - middleware form - and returns a

View File

@@ -36,7 +36,6 @@ func TestFromStd(t *testing.T) {
}
func TestFromStdWithNext(t *testing.T) {
basicauth := "secret"
passed := "ok"

View File

@@ -76,7 +76,6 @@ func (m myTestTask) OnServe(host TaskHost) {
time.AfterFunc(startDelay, func() {
m.logger.Println("restart")
host.Serve() // restart
})
}

View File

@@ -20,7 +20,6 @@ const (
)
func newTester(t *testing.T, baseURL string, handler http.Handler) *httpexpect.Expect {
var transporter http.RoundTripper
if strings.HasPrefix(baseURL, "http") { // means we are testing real serve time
@@ -57,9 +56,8 @@ func testSupervisor(t *testing.T, creator func(*http.Server, []func(TaskHost)) *
)
// http routing
var (
expectedBody = "this is the response body\n"
)
expectedBody := "this is the response body\n"
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
@@ -98,6 +96,7 @@ func testSupervisor(t *testing.T, creator func(*http.Server, []func(TaskHost)) *
t.Fatalf("expected hello Task's message to be '%s' but got '%s'", expectedHelloMessage, got)
}
}
func TestSupervisor(t *testing.T) {
testSupervisor(t, func(srv *http.Server, tasks []func(TaskHost)) *Supervisor {
su := New(srv)

View File

@@ -30,7 +30,6 @@ var IsLoopbackSubdomain = func(s string) bool {
if !strings.Contains(machineHostname, ".") { // if machine name's is not a loopback by itself
valid = s == machineHostname
}
}
return valid
}
@@ -96,10 +95,8 @@ const (
defaultServerPort = 8080
)
var (
// defaultServerAddr the default server addr which is: localhost:8080
defaultServerAddr = defaultServerHostname + ":" + strconv.Itoa(defaultServerPort)
)
// defaultServerAddr the default server addr which is: localhost:8080
var defaultServerAddr = defaultServerHostname + ":" + strconv.Itoa(defaultServerPort)
// ResolveAddr tries to convert a given string to an address which is compatible with net.Listener and server
func ResolveAddr(addr string) string {

View File

@@ -85,7 +85,6 @@ func UNIX(socketFile string, mode os.FileMode) (net.Listener, error) {
// TLS returns a new TLS Listener and an error on failure.
func TLS(addr, certFile, keyFile string) (net.Listener, error) {
if certFile == "" || keyFile == "" {
return nil, errCertKeyMissing
}

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) {