mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-16 00:35:10 +00:00
refactor: clean up form binding & validation (#38873)
Clarify the "validation" and "error display" logic. All the copied&pasted `Validate` functions are removed.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package structs
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"gitea.dev/modules/reqctx"
|
||||
"gitea.dev/modules/translation/i18n"
|
||||
|
||||
"gitea.com/go-chi/binding"
|
||||
)
|
||||
|
||||
// ValidateContext is a special context for form validation middleware
|
||||
type ValidateContext struct {
|
||||
Locale i18n.LocaleTranslation
|
||||
Data reqctx.ContextData
|
||||
Req *http.Request
|
||||
Resp http.ResponseWriter
|
||||
}
|
||||
|
||||
type FormDefaultValidator struct{}
|
||||
|
||||
func (FormDefaultValidator) Validate(ctx *ValidateContext, errs binding.Errors) binding.Errors {
|
||||
// this default validator only needs to return the errs as is because the "binding" function has already validated
|
||||
return errs
|
||||
}
|
||||
Reference in New Issue
Block a user