summaryrefslogtreecommitdiffstats
path: root/modules/web/route.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/web/route.go')
-rw-r--r--modules/web/route.go34
1 files changed, 17 insertions, 17 deletions
diff --git a/modules/web/route.go b/modules/web/route.go
index 86e407701c..4341b1bf5d 100644
--- a/modules/web/route.go
+++ b/modules/web/route.go
@@ -20,7 +20,7 @@ import (
// Bind binding an obj to a handler
func Bind(obj interface{}) http.HandlerFunc {
- var tp = reflect.TypeOf(obj)
+ tp := reflect.TypeOf(obj)
if tp.Kind() == reflect.Ptr {
tp = tp.Elem()
}
@@ -28,7 +28,7 @@ func Bind(obj interface{}) http.HandlerFunc {
panic("Only structs are allowed to bind")
}
return Wrap(func(ctx *context.Context) {
- var theObj = reflect.New(tp).Interface() // create a new form obj for every request but not use obj directly
+ theObj := reflect.New(tp).Interface() // create a new form obj for every request but not use obj directly
binding.Bind(ctx.Req, theObj)
SetForm(ctx, theObj)
middleware.AssignForm(theObj, ctx.Data)
@@ -86,8 +86,8 @@ func (r *Route) Use(middlewares ...interface{}) {
// Group mounts a sub-Router along a `pattern` string.
func (r *Route) Group(pattern string, fn func(), middlewares ...interface{}) {
- var previousGroupPrefix = r.curGroupPrefix
- var previousMiddlewares = r.curMiddlewares
+ previousGroupPrefix := r.curGroupPrefix
+ previousMiddlewares := r.curMiddlewares
r.curGroupPrefix += pattern
r.curMiddlewares = append(r.curMiddlewares, middlewares...)
@@ -110,7 +110,7 @@ func (r *Route) getPattern(pattern string) string {
// Mount attaches another Route along ./pattern/*
func (r *Route) Mount(pattern string, subR *Route) {
- var middlewares = make([]interface{}, len(r.curMiddlewares))
+ middlewares := make([]interface{}, len(r.curMiddlewares))
copy(middlewares, r.curMiddlewares)
subR.Use(middlewares...)
r.R.Mount(r.getPattern(pattern), subR.R)
@@ -118,7 +118,7 @@ func (r *Route) Mount(pattern string, subR *Route) {
// Any delegate requests for all methods
func (r *Route) Any(pattern string, h ...interface{}) {
- var middlewares = r.getMiddlewares(h)
+ middlewares := r.getMiddlewares(h)
r.R.HandleFunc(r.getPattern(pattern), Wrap(middlewares...))
}
@@ -126,7 +126,7 @@ func (r *Route) Any(pattern string, h ...interface{}) {
func (r *Route) Route(pattern, methods string, h ...interface{}) {
p := r.getPattern(pattern)
ms := strings.Split(methods, ",")
- var middlewares = r.getMiddlewares(h)
+ middlewares := r.getMiddlewares(h)
for _, method := range ms {
r.R.MethodFunc(strings.TrimSpace(method), p, Wrap(middlewares...))
}
@@ -134,12 +134,12 @@ func (r *Route) Route(pattern, methods string, h ...interface{}) {
// Delete delegate delete method
func (r *Route) Delete(pattern string, h ...interface{}) {
- var middlewares = r.getMiddlewares(h)
+ middlewares := r.getMiddlewares(h)
r.R.Delete(r.getPattern(pattern), Wrap(middlewares...))
}
func (r *Route) getMiddlewares(h []interface{}) []interface{} {
- var middlewares = make([]interface{}, len(r.curMiddlewares), len(r.curMiddlewares)+len(h))
+ middlewares := make([]interface{}, len(r.curMiddlewares), len(r.curMiddlewares)+len(h))
copy(middlewares, r.curMiddlewares)
middlewares = append(middlewares, h...)
return middlewares
@@ -147,51 +147,51 @@ func (r *Route) getMiddlewares(h []interface{}) []interface{} {
// Get delegate get method
func (r *Route) Get(pattern string, h ...interface{}) {
- var middlewares = r.getMiddlewares(h)
+ middlewares := r.getMiddlewares(h)
r.R.Get(r.getPattern(pattern), Wrap(middlewares...))
}
// Options delegate options method
func (r *Route) Options(pattern string, h ...interface{}) {
- var middlewares = r.getMiddlewares(h)
+ middlewares := r.getMiddlewares(h)
r.R.Options(r.getPattern(pattern), Wrap(middlewares...))
}
// GetOptions delegate get and options method
func (r *Route) GetOptions(pattern string, h ...interface{}) {
- var middlewares = r.getMiddlewares(h)
+ middlewares := r.getMiddlewares(h)
r.R.Get(r.getPattern(pattern), Wrap(middlewares...))
r.R.Options(r.getPattern(pattern), Wrap(middlewares...))
}
// PostOptions delegate post and options method
func (r *Route) PostOptions(pattern string, h ...interface{}) {
- var middlewares = r.getMiddlewares(h)
+ middlewares := r.getMiddlewares(h)
r.R.Post(r.getPattern(pattern), Wrap(middlewares...))
r.R.Options(r.getPattern(pattern), Wrap(middlewares...))
}
// Head delegate head method
func (r *Route) Head(pattern string, h ...interface{}) {
- var middlewares = r.getMiddlewares(h)
+ middlewares := r.getMiddlewares(h)
r.R.Head(r.getPattern(pattern), Wrap(middlewares...))
}
// Post delegate post method
func (r *Route) Post(pattern string, h ...interface{}) {
- var middlewares = r.getMiddlewares(h)
+ middlewares := r.getMiddlewares(h)
r.R.Post(r.getPattern(pattern), Wrap(middlewares...))
}
// Put delegate put method
func (r *Route) Put(pattern string, h ...interface{}) {
- var middlewares = r.getMiddlewares(h)
+ middlewares := r.getMiddlewares(h)
r.R.Put(r.getPattern(pattern), Wrap(middlewares...))
}
// Patch delegate patch method
func (r *Route) Patch(pattern string, h ...interface{}) {
- var middlewares = r.getMiddlewares(h)
+ middlewares := r.getMiddlewares(h)
r.R.Patch(r.getPattern(pattern), Wrap(middlewares...))
}