summaryrefslogtreecommitdiffstats
path: root/modules/web
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2022-01-20 18:46:10 +0100
committerGitHub <noreply@github.com>2022-01-20 18:46:10 +0100
commit54e9ee37a7a301dbe74d46fd3c87712e6120e9bf (patch)
tree1be12fb072625c1b896b9d72f7912b018aad502b /modules/web
parent1d98d205f5825f40110e6628b61a97c91ac7f72d (diff)
downloadgitea-54e9ee37a7a301dbe74d46fd3c87712e6120e9bf.tar.gz
gitea-54e9ee37a7a301dbe74d46fd3c87712e6120e9bf.zip
format with gofumpt (#18184)
* gofumpt -w -l . * gofumpt -w -l -extra . * Add linter * manual fix * change make fmt
Diffstat (limited to 'modules/web')
-rw-r--r--modules/web/middleware/flash.go6
-rw-r--r--modules/web/middleware/locale.go2
-rw-r--r--modules/web/route.go34
-rw-r--r--modules/web/routing/context.go5
-rw-r--r--modules/web/routing/funcinfo.go8
-rw-r--r--modules/web/routing/logger_manager.go6
-rw-r--r--modules/web/wrap_convert.go2
7 files changed, 31 insertions, 32 deletions
diff --git a/modules/web/middleware/flash.go b/modules/web/middleware/flash.go
index cd9b089b94..d1d4a864e3 100644
--- a/modules/web/middleware/flash.go
+++ b/modules/web/middleware/flash.go
@@ -14,10 +14,8 @@ const (
InfoFlash = "InfoMsg"
)
-var (
- // FlashNow FIXME:
- FlashNow bool
-)
+// FlashNow FIXME:
+var FlashNow bool
// Flash represents a one time data transfer between two requests.
type Flash struct {
diff --git a/modules/web/middleware/locale.go b/modules/web/middleware/locale.go
index ede38ef933..3daf5f32d4 100644
--- a/modules/web/middleware/locale.go
+++ b/modules/web/middleware/locale.go
@@ -18,7 +18,7 @@ import (
func Locale(resp http.ResponseWriter, req *http.Request) translation.Locale {
// 1. Check URL arguments.
lang := req.URL.Query().Get("lang")
- var changeLang = lang != ""
+ changeLang := lang != ""
// 2. Get language information from cookies.
if len(lang) == 0 {
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...))
}
diff --git a/modules/web/routing/context.go b/modules/web/routing/context.go
index f57b2e9026..d3c7759e64 100644
--- a/modules/web/routing/context.go
+++ b/modules/web/routing/context.go
@@ -13,7 +13,7 @@ type contextKeyType struct{}
var contextKey contextKeyType
-//UpdateFuncInfo updates a context's func info
+// UpdateFuncInfo updates a context's func info
func UpdateFuncInfo(ctx context.Context, funcInfo *FuncInfo) {
record, ok := ctx.Value(contextKey).(*requestRecord)
if !ok {
@@ -23,7 +23,6 @@ func UpdateFuncInfo(ctx context.Context, funcInfo *FuncInfo) {
record.lock.Lock()
record.funcInfo = funcInfo
record.lock.Unlock()
-
}
// MarkLongPolling marks the reuqest is a long-polling request, and the logger may output different message for it
@@ -38,7 +37,7 @@ func MarkLongPolling(resp http.ResponseWriter, req *http.Request) {
record.lock.Unlock()
}
-//UpdatePanicError updates a context's error info, a panic may be recovered by other middlewares, but we still need to know that.
+// UpdatePanicError updates a context's error info, a panic may be recovered by other middlewares, but we still need to know that.
func UpdatePanicError(ctx context.Context, err interface{}) {
record, ok := ctx.Value(contextKey).(*requestRecord)
if !ok {
diff --git a/modules/web/routing/funcinfo.go b/modules/web/routing/funcinfo.go
index 6d3986e364..9bb38af1c8 100644
--- a/modules/web/routing/funcinfo.go
+++ b/modules/web/routing/funcinfo.go
@@ -12,9 +12,11 @@ import (
"sync"
)
-var funcInfoMap = map[uintptr]*FuncInfo{}
-var funcInfoNameMap = map[string]*FuncInfo{}
-var funcInfoMapMu sync.RWMutex
+var (
+ funcInfoMap = map[uintptr]*FuncInfo{}
+ funcInfoNameMap = map[string]*FuncInfo{}
+ funcInfoMapMu sync.RWMutex
+)
// FuncInfo contains information about the function to be logged by the router log
type FuncInfo struct {
diff --git a/modules/web/routing/logger_manager.go b/modules/web/routing/logger_manager.go
index 31fd09f312..cc434c338d 100644
--- a/modules/web/routing/logger_manager.go
+++ b/modules/web/routing/logger_manager.go
@@ -17,13 +17,13 @@ import (
type Event int
const (
- //StartEvent at the beginning of a request
+ // StartEvent at the beginning of a request
StartEvent Event = iota
- //StillExecutingEvent the request is still executing
+ // StillExecutingEvent the request is still executing
StillExecutingEvent
- //EndEvent the request has ended (either completed or failed)
+ // EndEvent the request has ended (either completed or failed)
EndEvent
)
diff --git a/modules/web/wrap_convert.go b/modules/web/wrap_convert.go
index f2e05de7c1..d4a24b3ad4 100644
--- a/modules/web/wrap_convert.go
+++ b/modules/web/wrap_convert.go
@@ -87,7 +87,7 @@ func convertHandler(handler interface{}) wrappedHandlerFunc {
}
case func(http.Handler) http.Handler:
return func(resp http.ResponseWriter, req *http.Request, others ...wrappedHandlerFunc) (done bool, deferrable func()) {
- var next = http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})
+ next := http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})
if len(others) > 0 {
next = wrapInternal(others)
}