validator.go 735 B

1234567891011121314151617181920212223242526272829
  1. // Copyright 2021 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package validator // import "miniflux.app/validator"
  5. import (
  6. "errors"
  7. "miniflux.app/locale"
  8. )
  9. // ValidationError represents a validation error.
  10. type ValidationError struct {
  11. TranslationKey string
  12. }
  13. // NewValidationError initializes a validation error.
  14. func NewValidationError(translationKey string) *ValidationError {
  15. return &ValidationError{TranslationKey: translationKey}
  16. }
  17. func (v *ValidationError) String() string {
  18. return locale.NewPrinter("en_US").Printf(v.TranslationKey)
  19. }
  20. func (v *ValidationError) Error() error {
  21. return errors.New(v.String())
  22. }