mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-12 04:48:52 +00: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:
@@ -48,7 +48,7 @@ func CreateOrUpdateSecret(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
opt := web.GetForm(ctx).(*api.CreateOrUpdateSecretOption)
|
||||
opt := web.GetForm[*api.CreateOrUpdateSecretOption](ctx)
|
||||
|
||||
_, created, err := secret_service.CreateOrUpdateSecret(ctx, ctx.Doer.ID, 0, ctx.PathParam("secretname"), opt.Data, opt.Description)
|
||||
if err != nil {
|
||||
@@ -134,7 +134,7 @@ func CreateVariable(ctx *context.APIContext) {
|
||||
// "409":
|
||||
// description: variable name already exists.
|
||||
|
||||
opt := web.GetForm(ctx).(*api.CreateVariableOption)
|
||||
opt := web.GetForm[*api.CreateVariableOption](ctx)
|
||||
|
||||
ownerID := ctx.Doer.ID
|
||||
variableName := ctx.PathParam("variablename")
|
||||
@@ -193,7 +193,7 @@ func UpdateVariable(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
opt := web.GetForm(ctx).(*api.UpdateVariableOption)
|
||||
opt := web.GetForm[*api.UpdateVariableOption](ctx)
|
||||
|
||||
v, err := actions_service.GetVariable(ctx, actions_model.FindVariablesOpts{
|
||||
OwnerID: ctx.Doer.ID,
|
||||
|
||||
@@ -98,7 +98,7 @@ func CreateAccessToken(ctx *context.APIContext) {
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateAccessTokenOption)
|
||||
form := web.GetForm[*api.CreateAccessTokenOption](ctx)
|
||||
|
||||
t := &auth_model.AccessToken{
|
||||
UID: ctx.ContextUser.ID,
|
||||
@@ -242,7 +242,7 @@ func CreateOauth2Application(ctx *context.APIContext) {
|
||||
// "400":
|
||||
// "$ref": "#/responses/error"
|
||||
|
||||
data := web.GetForm(ctx).(*api.CreateOAuth2ApplicationOptions)
|
||||
data := web.GetForm[*api.CreateOAuth2ApplicationOptions](ctx)
|
||||
if invalidURI := forms.DetectInvalidOAuth2ApplicationRedirectURI(data.RedirectURIs); invalidURI != "" {
|
||||
ctx.APIError(http.StatusBadRequest, "invalid redirect URI: "+invalidURI)
|
||||
return
|
||||
@@ -406,7 +406,7 @@ func UpdateOauth2Application(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/notFound"
|
||||
appID := ctx.PathParamInt64("id")
|
||||
|
||||
data := web.GetForm(ctx).(*api.CreateOAuth2ApplicationOptions)
|
||||
data := web.GetForm[*api.CreateOAuth2ApplicationOptions](ctx)
|
||||
if invalidURI := forms.DetectInvalidOAuth2ApplicationRedirectURI(data.RedirectURIs); invalidURI != "" {
|
||||
ctx.APIError(http.StatusBadRequest, "invalid redirect URI: "+invalidURI)
|
||||
return
|
||||
|
||||
@@ -28,7 +28,7 @@ func UpdateAvatar(ctx *context.APIContext) {
|
||||
// responses:
|
||||
// "204":
|
||||
// "$ref": "#/responses/empty"
|
||||
form := web.GetForm(ctx).(*api.UpdateUserAvatarOption)
|
||||
form := web.GetForm[*api.UpdateUserAvatarOption](ctx)
|
||||
|
||||
content, err := base64.StdEncoding.DecodeString(form.Image)
|
||||
if err != nil {
|
||||
|
||||
@@ -63,15 +63,15 @@ func AddEmail(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateEmailOption)
|
||||
form := web.GetForm[*api.CreateEmailOption](ctx)
|
||||
if len(form.Emails) == 0 {
|
||||
ctx.APIError(http.StatusUnprocessableEntity, "Email list empty")
|
||||
return
|
||||
}
|
||||
|
||||
if err := user_service.AddEmailAddresses(ctx, ctx.Doer, form.Emails); err != nil {
|
||||
if user_model.IsErrEmailAlreadyUsed(err) {
|
||||
ctx.APIError(http.StatusUnprocessableEntity, "Email address has been used: "+err.(user_model.ErrEmailAlreadyUsed).Email)
|
||||
if errEmailAlreadyUsed, ok := err.(user_model.ErrEmailAlreadyUsed); ok {
|
||||
ctx.APIError(http.StatusUnprocessableEntity, "Email address has been used: "+errEmailAlreadyUsed.Email)
|
||||
} else if user_model.IsErrEmailCharIsNotSupported(err) || user_model.IsErrEmailInvalid(err) {
|
||||
email := ""
|
||||
if typedError, ok := err.(user_model.ErrEmailInvalid); ok {
|
||||
@@ -125,7 +125,7 @@ func DeleteEmail(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
form := web.GetForm(ctx).(*api.DeleteEmailOption)
|
||||
form := web.GetForm[*api.DeleteEmailOption](ctx)
|
||||
if len(form.Emails) == 0 {
|
||||
ctx.Status(http.StatusNoContent)
|
||||
return
|
||||
|
||||
@@ -187,7 +187,7 @@ func VerifyUserGPGKey(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.VerifyGPGKeyOption)
|
||||
form := web.GetForm[*api.VerifyGPGKeyOption](ctx)
|
||||
token := asymkey_model.VerificationToken(ctx.Doer, 1)
|
||||
lastToken := asymkey_model.VerificationToken(ctx.Doer, 0)
|
||||
|
||||
@@ -248,7 +248,7 @@ func CreateGPGKey(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateGPGKeyOption)
|
||||
form := web.GetForm[*api.CreateGPGKeyOption](ctx)
|
||||
CreateUserGPGKey(ctx, *form, ctx.Doer.ID)
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ func CreateHook(ctx *context.APIContext) {
|
||||
utils.AddOwnerHook(
|
||||
ctx,
|
||||
ctx.Doer,
|
||||
web.GetForm(ctx).(*api.CreateHookOption),
|
||||
web.GetForm[*api.CreateHookOption](ctx),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ func EditHook(ctx *context.APIContext) {
|
||||
utils.EditOwnerHook(
|
||||
ctx,
|
||||
ctx.Doer,
|
||||
web.GetForm(ctx).(*api.EditHookOption),
|
||||
web.GetForm[*api.EditHookOption](ctx),
|
||||
ctx.PathParamInt64("id"),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ func CreatePublicKey(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateKeyOption)
|
||||
form := web.GetForm[*api.CreateKeyOption](ctx)
|
||||
CreateUserPublicKey(ctx, *form, ctx.Doer.ID)
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ func UpdateUserSettings(ctx *context.APIContext) {
|
||||
// "200":
|
||||
// "$ref": "#/responses/UserSettings"
|
||||
|
||||
form := web.GetForm(ctx).(*api.UserSettingsOptions)
|
||||
form := web.GetForm[*api.UserSettingsOptions](ctx)
|
||||
|
||||
opts := &user_service.UpdateOptions{
|
||||
FullName: optional.FromPtr(form.FullName),
|
||||
|
||||
Reference in New Issue
Block a user