mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-15 18:46: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:
@@ -4,16 +4,12 @@
|
||||
package forms
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"gitea.dev/modules/optional"
|
||||
"gitea.dev/modules/web/middleware"
|
||||
"gitea.dev/services/context"
|
||||
|
||||
"gitea.com/go-chi/binding"
|
||||
)
|
||||
|
||||
type CommitCommonForm struct {
|
||||
middleware.FormDefaultValidator
|
||||
TreePath string `binding:"MaxSize(500)"`
|
||||
CommitSummary string `binding:"MaxSize(100)"`
|
||||
CommitMessage string
|
||||
@@ -24,11 +20,6 @@ type CommitCommonForm struct {
|
||||
CommitEmail string
|
||||
}
|
||||
|
||||
func (f *CommitCommonForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
type CommitCommonFormInterface interface {
|
||||
GetCommitCommonForm() *CommitCommonForm
|
||||
}
|
||||
@@ -38,20 +29,24 @@ func (f *CommitCommonForm) GetCommitCommonForm() *CommitCommonForm {
|
||||
}
|
||||
|
||||
type EditRepoFileForm struct {
|
||||
middleware.FormDefaultValidator
|
||||
CommitCommonForm
|
||||
Content optional.Option[string]
|
||||
}
|
||||
|
||||
type DeleteRepoFileForm struct {
|
||||
middleware.FormDefaultValidator
|
||||
CommitCommonForm
|
||||
}
|
||||
|
||||
type UploadRepoFileForm struct {
|
||||
middleware.FormDefaultValidator
|
||||
CommitCommonForm
|
||||
Files []string
|
||||
}
|
||||
|
||||
type CherryPickForm struct {
|
||||
middleware.FormDefaultValidator
|
||||
CommitCommonForm
|
||||
Revert bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user