mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-08 22:13:26 +09:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user