chore: enable forcetypeassert linter, fix issues (#38804)

Enable [`forcetypeassert`](https://github.com/gostaticanalysis/forcetypeassert)
linter to prevent unchecked type assertions. ~650 issues fixed, most
fixes were clean, some use `setting.PanicInDevOrTesting`.

The only behaviour changes are where code would previously send a 500 error
or panic, a 4xx error is now emitted.

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
silverwind
2026-08-09 10:25:06 +00:00
committed by GitHub
co-authored by wxiaoguang
parent fac8bf2eca
commit 76a81b24f9
248 changed files with 1110 additions and 995 deletions
+3 -2
View File
@@ -13,6 +13,7 @@ import (
"gitea.dev/modules/log"
"gitea.dev/modules/private"
"gitea.dev/modules/process"
"gitea.dev/modules/reqctx"
"gitea.dev/modules/web"
web_types "gitea.dev/modules/web/types"
)
@@ -27,7 +28,7 @@ type PrivateContext struct {
func init() {
web.RegisterResponseStatusProvider[*PrivateContext](func(req *http.Request) web_types.ResponseStatusProvider {
return req.Context().Value(privateContextKey).(*PrivateContext)
return GetPrivateContext(req)
})
}
@@ -67,7 +68,7 @@ type privateContextKeyType struct{}
var privateContextKey privateContextKeyType
func GetPrivateContext(req *http.Request) *PrivateContext {
return req.Context().Value(privateContextKey).(*PrivateContext)
return reqctx.MustContextValue[*PrivateContext](req.Context(), privateContextKey)
}
func PrivateContexter() func(http.Handler) http.Handler {