aboutsummaryrefslogtreecommitdiffstats
path: root/modules/context
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/context
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/context')
-rw-r--r--modules/context/api.go21
-rw-r--r--modules/context/api_test.go2
-rw-r--r--modules/context/captcha.go6
-rw-r--r--modules/context/context.go14
-rw-r--r--modules/context/csrf.go4
-rw-r--r--modules/context/private.go4
-rw-r--r--modules/context/repo.go1
-rw-r--r--modules/context/response.go4
8 files changed, 26 insertions, 30 deletions
diff --git a/modules/context/api.go b/modules/context/api.go
index dae6d23989..c825e48753 100644
--- a/modules/context/api.go
+++ b/modules/context/api.go
@@ -56,29 +56,29 @@ type APIInvalidTopicsError struct {
InvalidTopics []string `json:"invalidTopics"`
}
-//APIEmpty is an empty response
+// APIEmpty is an empty response
// swagger:response empty
type APIEmpty struct{}
-//APIForbiddenError is a forbidden error response
+// APIForbiddenError is a forbidden error response
// swagger:response forbidden
type APIForbiddenError struct {
APIError
}
-//APINotFound is a not found empty response
+// APINotFound is a not found empty response
// swagger:response notFound
type APINotFound struct{}
-//APIConflict is a conflict empty response
+// APIConflict is a conflict empty response
// swagger:response conflict
type APIConflict struct{}
-//APIRedirect is a redirect response
+// APIRedirect is a redirect response
// swagger:response redirect
type APIRedirect struct{}
-//APIString is a string response
+// APIString is a string response
// swagger:response string
type APIString string
@@ -269,13 +269,12 @@ func APIAuth(authMethod auth_service.Method) func(*APIContext) {
// APIContexter returns apicontext as middleware
func APIContexter() func(http.Handler) http.Handler {
- var csrfOpts = getCsrfOpts()
+ csrfOpts := getCsrfOpts()
return func(next http.Handler) http.Handler {
-
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
- var locale = middleware.Locale(w, req)
- var ctx = APIContext{
+ locale := middleware.Locale(w, req)
+ ctx := APIContext{
Context: &Context{
Resp: NewResponse(w),
Data: map[string]interface{}{},
@@ -354,7 +353,7 @@ func ReferencesGitRepo(allowEmpty bool) func(ctx *APIContext) (cancel context.Ca
// NotFound handles 404s for APIContext
// String will replace message, errors will be added to a slice
func (ctx *APIContext) NotFound(objs ...interface{}) {
- var message = ctx.Tr("error.not_found")
+ message := ctx.Tr("error.not_found")
var errors []string
for _, obj := range objs {
// Ignore nil
diff --git a/modules/context/api_test.go b/modules/context/api_test.go
index e7e3e230af..323fdbd2cc 100644
--- a/modules/context/api_test.go
+++ b/modules/context/api_test.go
@@ -16,7 +16,7 @@ import (
func TestGenAPILinks(t *testing.T) {
setting.AppURL = "http://localhost:3000/"
- var kases = map[string][]string{
+ kases := map[string][]string{
"api/v1/repos/jerrykan/example-repo/issues?state=all": {
`<http://localhost:3000/api/v1/repos/jerrykan/example-repo/issues?page=2&state=all>; rel="next"`,
`<http://localhost:3000/api/v1/repos/jerrykan/example-repo/issues?page=5&state=all>; rel="last"`,
diff --git a/modules/context/captcha.go b/modules/context/captcha.go
index b8540136a1..6117d30713 100644
--- a/modules/context/captcha.go
+++ b/modules/context/captcha.go
@@ -13,8 +13,10 @@ import (
"gitea.com/go-chi/captcha"
)
-var imageCaptchaOnce sync.Once
-var cpt *captcha.Captcha
+var (
+ imageCaptchaOnce sync.Once
+ cpt *captcha.Captcha
+)
// GetImageCaptcha returns global image captcha
func GetImageCaptcha() *captcha.Captcha {
diff --git a/modules/context/context.go b/modules/context/context.go
index ab83ae4eb5..998eafe965 100644
--- a/modules/context/context.go
+++ b/modules/context/context.go
@@ -362,7 +362,7 @@ func (ctx *Context) ServeStream(rd io.Reader, name string) {
// Error returned an error to web browser
func (ctx *Context) Error(status int, contents ...string) {
- var v = http.StatusText(status)
+ v := http.StatusText(status)
if len(contents) > 0 {
v = contents[0]
}
@@ -606,16 +606,16 @@ func Auth(authMethod auth.Method) func(*Context) {
// Contexter initializes a classic context for a request.
func Contexter() func(next http.Handler) http.Handler {
- var rnd = templates.HTMLRenderer()
- var csrfOpts = getCsrfOpts()
+ rnd := templates.HTMLRenderer()
+ csrfOpts := getCsrfOpts()
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
- var locale = middleware.Locale(resp, req)
- var startTime = time.Now()
- var link = setting.AppSubURL + strings.TrimSuffix(req.URL.EscapedPath(), "/")
+ locale := middleware.Locale(resp, req)
+ startTime := time.Now()
+ link := setting.AppSubURL + strings.TrimSuffix(req.URL.EscapedPath(), "/")
- var ctx = Context{
+ ctx := Context{
Resp: NewResponse(resp),
Cache: mc.GetCache(),
Locale: locale,
diff --git a/modules/context/csrf.go b/modules/context/csrf.go
index 8d179ca904..99c223c884 100644
--- a/modules/context/csrf.go
+++ b/modules/context/csrf.go
@@ -57,9 +57,9 @@ type csrf struct {
Form string
// Cookie name value for setting and getting csrf token.
Cookie string
- //Cookie domain
+ // Cookie domain
CookieDomain string
- //Cookie path
+ // Cookie path
CookiePath string
// Cookie HttpOnly flag value used for the csrf token.
CookieHTTPOnly bool
diff --git a/modules/context/private.go b/modules/context/private.go
index 3e31a7e7d8..6e5ef1bd12 100644
--- a/modules/context/private.go
+++ b/modules/context/private.go
@@ -44,9 +44,7 @@ func (ctx *PrivateContext) Err() error {
return ctx.Req.Context().Err()
}
-var (
- privateContextKey interface{} = "default_private_context"
-)
+var privateContextKey interface{} = "default_private_context"
// WithPrivateContext set up private context in request
func WithPrivateContext(req *http.Request, ctx *PrivateContext) *http.Request {
diff --git a/modules/context/repo.go b/modules/context/repo.go
index 4acb800b64..97b417ffd1 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -111,7 +111,6 @@ type CanCommitToBranchResults struct {
// and branch is not protected for push
func (r *Repository) CanCommitToBranch(ctx context.Context, doer *user_model.User) (CanCommitToBranchResults, error) {
protectedBranch, err := models.GetProtectedBranchBy(r.Repository.ID, r.BranchName)
-
if err != nil {
return CanCommitToBranchResults{}, err
}
diff --git a/modules/context/response.go b/modules/context/response.go
index a20fc63536..112964dbe1 100644
--- a/modules/context/response.go
+++ b/modules/context/response.go
@@ -17,9 +17,7 @@ type ResponseWriter interface {
Size() int
}
-var (
- _ ResponseWriter = &Response{}
-)
+var _ ResponseWriter = &Response{}
// Response represents a response
type Response struct {