aboutsummaryrefslogtreecommitdiffstats
path: root/modules/context
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2023-07-04 20:36:08 +0200
committerGitHub <noreply@github.com>2023-07-04 18:36:08 +0000
commit88f835192d1a554d233b0ec4daa33276b7eb2910 (patch)
tree438140c295791e64a3b78dcfeae57701bcf296c3 /modules/context
parent00dbba7f4266032a2b91b760e7c611950ffad096 (diff)
downloadgitea-88f835192d1a554d233b0ec4daa33276b7eb2910.tar.gz
gitea-88f835192d1a554d233b0ec4daa33276b7eb2910.zip
Replace `interface{}` with `any` (#25686)
Result of running `perl -p -i -e 's#interface\{\}#any#g' **/*` and `make fmt`. Basically the same [as golang did](https://github.com/golang/go/commit/2580d0e08d5e9f979b943758d3c49877fb2324cb).
Diffstat (limited to 'modules/context')
-rw-r--r--modules/context/access_log.go4
-rw-r--r--modules/context/api.go6
-rw-r--r--modules/context/base.go2
-rw-r--r--modules/context/captcha.go2
-rw-r--r--modules/context/context.go4
-rw-r--r--modules/context/context_response.go4
-rw-r--r--modules/context/package.go4
-rw-r--r--modules/context/pagination.go2
-rw-r--r--modules/context/permission.go2
-rw-r--r--modules/context/private.go2
10 files changed, 16 insertions, 16 deletions
diff --git a/modules/context/access_log.go b/modules/context/access_log.go
index 373574ba14..0926748ac5 100644
--- a/modules/context/access_log.go
+++ b/modules/context/access_log.go
@@ -23,7 +23,7 @@ type routerLoggerOptions struct {
Identity *string
Start *time.Time
ResponseWriter http.ResponseWriter
- Ctx map[string]interface{}
+ Ctx map[string]any
RequestID *string
}
@@ -84,7 +84,7 @@ func AccessLogger() func(http.Handler) http.Handler {
Identity: &identity,
Start: &start,
ResponseWriter: rw,
- Ctx: map[string]interface{}{
+ Ctx: map[string]any{
"RemoteAddr": req.RemoteAddr,
"RemoteHost": reqHost,
"Req": req,
diff --git a/modules/context/api.go b/modules/context/api.go
index 3c4d020413..93a587d436 100644
--- a/modules/context/api.go
+++ b/modules/context/api.go
@@ -108,7 +108,7 @@ func (ctx *APIContext) ServerError(title string, err error) {
// Error responds with an error message to client with given obj as the message.
// If status is 500, also it prints error to log.
-func (ctx *APIContext) Error(status int, title string, obj interface{}) {
+func (ctx *APIContext) Error(status int, title string, obj any) {
var message string
if err, ok := obj.(error); ok {
message = err.Error()
@@ -265,7 +265,7 @@ func APIContexter() func(http.Handler) http.Handler {
// NotFound handles 404s for APIContext
// String will replace message, errors will be added to a slice
-func (ctx *APIContext) NotFound(objs ...interface{}) {
+func (ctx *APIContext) NotFound(objs ...any) {
message := ctx.Tr("error.not_found")
var errors []string
for _, obj := range objs {
@@ -281,7 +281,7 @@ func (ctx *APIContext) NotFound(objs ...interface{}) {
}
}
- ctx.JSON(http.StatusNotFound, map[string]interface{}{
+ ctx.JSON(http.StatusNotFound, map[string]any{
"message": message,
"url": setting.API.SwaggerURL,
"errors": errors,
diff --git a/modules/context/base.go b/modules/context/base.go
index 839f3e10df..8566ef7861 100644
--- a/modules/context/base.go
+++ b/modules/context/base.go
@@ -128,7 +128,7 @@ func (b *Base) Error(status int, contents ...string) {
}
// JSON render content as JSON
-func (b *Base) JSON(status int, content interface{}) {
+func (b *Base) JSON(status int, content any) {
b.Resp.Header().Set("Content-Type", "application/json;charset=utf-8")
b.Resp.WriteHeader(status)
if err := json.NewEncoder(b.Resp).Encode(content); err != nil {
diff --git a/modules/context/captcha.go b/modules/context/captcha.go
index 07232e9390..a1999900c9 100644
--- a/modules/context/captcha.go
+++ b/modules/context/captcha.go
@@ -60,7 +60,7 @@ const (
// VerifyCaptcha verifies Captcha data
// No-op if captchas are not enabled
-func VerifyCaptcha(ctx *Context, tpl base.TplName, form interface{}) {
+func VerifyCaptcha(ctx *Context, tpl base.TplName, form any) {
if !setting.Service.EnableCaptcha {
return
}
diff --git a/modules/context/context.go b/modules/context/context.go
index 93d448fca5..47a04c989c 100644
--- a/modules/context/context.go
+++ b/modules/context/context.go
@@ -32,7 +32,7 @@ import (
// Render represents a template render
type Render interface {
TemplateLookup(tmpl string) (templates.TemplateExecutor, error)
- HTML(w io.Writer, status int, name string, data interface{}) error
+ HTML(w io.Writer, status int, name string, data any) error
}
// Context represents context of a request.
@@ -69,7 +69,7 @@ func init() {
// TrHTMLEscapeArgs runs ".Locale.Tr()" but pre-escapes all arguments with html.EscapeString.
// This is useful if the locale message is intended to only produce HTML content.
func (ctx *Context) TrHTMLEscapeArgs(msg string, args ...string) string {
- trArgs := make([]interface{}, len(args))
+ trArgs := make([]any, len(args))
for i, arg := range args {
trArgs[i] = html.EscapeString(arg)
}
diff --git a/modules/context/context_response.go b/modules/context/context_response.go
index 88e375986c..bb3ccf69ce 100644
--- a/modules/context/context_response.go
+++ b/modules/context/context_response.go
@@ -91,14 +91,14 @@ func (ctx *Context) HTML(status int, name base.TplName) {
}
// RenderToString renders the template content to a string
-func (ctx *Context) RenderToString(name base.TplName, data map[string]interface{}) (string, error) {
+func (ctx *Context) RenderToString(name base.TplName, data map[string]any) (string, error) {
var buf strings.Builder
err := ctx.Render.HTML(&buf, http.StatusOK, string(name), data)
return buf.String(), err
}
// RenderWithErr used for page has form validation but need to prompt error to users.
-func (ctx *Context) RenderWithErr(msg string, tpl base.TplName, form interface{}) {
+func (ctx *Context) RenderWithErr(msg string, tpl base.TplName, form any) {
if form != nil {
middleware.AssignForm(form, ctx.Data)
}
diff --git a/modules/context/package.go b/modules/context/package.go
index 8052032787..8e80fa66ec 100644
--- a/modules/context/package.go
+++ b/modules/context/package.go
@@ -33,7 +33,7 @@ type packageAssignmentCtx struct {
// PackageAssignment returns a middleware to handle Context.Package assignment
func PackageAssignment() func(ctx *Context) {
return func(ctx *Context) {
- errorFn := func(status int, title string, obj interface{}) {
+ errorFn := func(status int, title string, obj any) {
err, ok := obj.(error)
if !ok {
err = fmt.Errorf("%s", obj)
@@ -57,7 +57,7 @@ func PackageAssignmentAPI() func(ctx *APIContext) {
}
}
-func packageAssignment(ctx *packageAssignmentCtx, errCb func(int, string, interface{})) *Package {
+func packageAssignment(ctx *packageAssignmentCtx, errCb func(int, string, any)) *Package {
pkg := &Package{
Owner: ctx.ContextUser,
}
diff --git a/modules/context/pagination.go b/modules/context/pagination.go
index 5a88c92053..68237c630c 100644
--- a/modules/context/pagination.go
+++ b/modules/context/pagination.go
@@ -32,7 +32,7 @@ func (p *Pagination) AddParam(ctx *Context, paramKey, ctxKey string) {
if !exists {
return
}
- paramData := fmt.Sprintf("%v", ctx.Data[ctxKey]) // cast interface{} to string
+ paramData := fmt.Sprintf("%v", ctx.Data[ctxKey]) // cast any to string
urlParam := fmt.Sprintf("%s=%v", url.QueryEscape(paramKey), url.QueryEscape(paramData))
p.urlParams = append(p.urlParams, urlParam)
}
diff --git a/modules/context/permission.go b/modules/context/permission.go
index 0f72b8e244..09343b8b50 100644
--- a/modules/context/permission.go
+++ b/modules/context/permission.go
@@ -90,7 +90,7 @@ func RequireRepoReaderOr(unitTypes ...unit.Type) func(ctx *Context) {
}
if log.IsTrace() {
var format string
- var args []interface{}
+ var args []any
if ctx.IsSigned {
format = "Permission Denied: User %-v cannot read ["
args = append(args, ctx.Doer)
diff --git a/modules/context/private.go b/modules/context/private.go
index 2e9b31140a..8b41949f60 100644
--- a/modules/context/private.go
+++ b/modules/context/private.go
@@ -53,7 +53,7 @@ func (ctx *PrivateContext) Err() error {
return ctx.Base.Err()
}
-var privateContextKey interface{} = "default_private_context"
+var privateContextKey any = "default_private_context"
// GetPrivateContext returns a context for Private routes
func GetPrivateContext(req *http.Request) *PrivateContext {