EventManager: add "on-demand" trigger

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2023-01-21 15:41:24 +01:00
parent 53f17b5715
commit 7b5bebc588
20 changed files with 410 additions and 49 deletions

View File

@@ -24,6 +24,14 @@ const (
"sftpgo serve -c \"<path to dir containing the default config file and templates directory>\""
)
// errors definitions
var (
ErrValidation = NewValidationError("")
ErrNotFound = NewRecordNotFoundError("")
ErrMethodDisabled = NewMethodDisabledError("")
ErrGeneric = NewGenericError("")
)
// ValidationError raised if input data is not valid
type ValidationError struct {
err string
@@ -39,6 +47,12 @@ func (e *ValidationError) GetErrorString() string {
return e.err
}
// Is reports if target matches
func (e *ValidationError) Is(target error) bool {
_, ok := target.(*ValidationError)
return ok
}
// NewValidationError returns a validation errors
func NewValidationError(error string) *ValidationError {
return &ValidationError{
@@ -55,6 +69,12 @@ func (e *RecordNotFoundError) Error() string {
return fmt.Sprintf("not found: %s", e.err)
}
// Is reports if target matches
func (e *RecordNotFoundError) Is(target error) bool {
_, ok := target.(*RecordNotFoundError)
return ok
}
// NewRecordNotFoundError returns a not found error
func NewRecordNotFoundError(error string) *RecordNotFoundError {
return &RecordNotFoundError{
@@ -74,6 +94,12 @@ func (e *MethodDisabledError) Error() string {
return fmt.Sprintf("Method disabled error: %s", e.err)
}
// Is reports if target matches
func (e *MethodDisabledError) Is(target error) bool {
_, ok := target.(*MethodDisabledError)
return ok
}
// NewMethodDisabledError returns a method disabled error
func NewMethodDisabledError(error string) *MethodDisabledError {
return &MethodDisabledError{
@@ -90,6 +116,12 @@ func (e *GenericError) Error() string {
return e.err
}
// Is reports if target matches
func (e *GenericError) Is(target error) bool {
_, ok := target.(*GenericError)
return ok
}
// NewGenericError returns a generic error
func NewGenericError(error string) *GenericError {
return &GenericError{