mirror of
https://github.com/miniflux/v2.git
synced 2025-08-26 18:21:01 +00:00
Refactor user validation
Validate each user field for creation/modification via API and web UI
This commit is contained in:
parent
291bf96d15
commit
e45cc2d2aa
40 changed files with 567 additions and 400 deletions
29
validator/validator.go
Normal file
29
validator/validator.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
// Copyright 2021 Frédéric Guillot. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package validator // import "miniflux.app/validator"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"miniflux.app/locale"
|
||||
)
|
||||
|
||||
// ValidationError represents a validation error.
|
||||
type ValidationError struct {
|
||||
TranslationKey string
|
||||
}
|
||||
|
||||
// NewValidationError initializes a validation error.
|
||||
func NewValidationError(translationKey string) *ValidationError {
|
||||
return &ValidationError{TranslationKey: translationKey}
|
||||
}
|
||||
|
||||
func (v *ValidationError) String() string {
|
||||
return locale.NewPrinter("en_US").Printf(v.TranslationKey)
|
||||
}
|
||||
|
||||
func (v *ValidationError) Error() error {
|
||||
return errors.New(v.String())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue