2022-07-12 12:42:06 +02:00
|
|
|
// Package models implements various services used for request data
|
|
|
|
// validation and applying changes to existing DB models through the app Dao.
|
|
|
|
package forms
|
|
|
|
|
2022-10-30 10:28:14 +02:00
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
)
|
2022-08-11 09:29:01 +02:00
|
|
|
|
|
|
|
// base ID value regex pattern
|
|
|
|
var idRegex = regexp.MustCompile(`^[^\@\#\$\&\|\.\,\'\"\\\/\s]+$`)
|
|
|
|
|
2022-07-12 12:42:06 +02:00
|
|
|
// InterceptorNextFunc is a interceptor handler function.
|
|
|
|
// Usually used in combination with InterceptorFunc.
|
2023-01-15 17:00:28 +02:00
|
|
|
type InterceptorNextFunc[T any] func(t T) error
|
2022-07-12 12:42:06 +02:00
|
|
|
|
2022-12-03 14:50:02 +02:00
|
|
|
// InterceptorFunc defines a single interceptor function that
|
|
|
|
// will execute the provided next func handler.
|
2023-01-15 17:00:28 +02:00
|
|
|
type InterceptorFunc[T any] func(next InterceptorNextFunc[T]) InterceptorNextFunc[T]
|
2022-07-12 12:42:06 +02:00
|
|
|
|
|
|
|
// runInterceptors executes the provided list of interceptors.
|
2023-01-15 17:00:28 +02:00
|
|
|
func runInterceptors[T any](
|
|
|
|
data T,
|
|
|
|
next InterceptorNextFunc[T],
|
|
|
|
interceptors ...InterceptorFunc[T],
|
|
|
|
) error {
|
2022-07-12 12:42:06 +02:00
|
|
|
for i := len(interceptors) - 1; i >= 0; i-- {
|
|
|
|
next = interceptors[i](next)
|
|
|
|
}
|
2022-12-03 14:50:02 +02:00
|
|
|
|
2023-01-15 17:00:28 +02:00
|
|
|
return next(data)
|
2022-12-03 14:50:02 +02:00
|
|
|
}
|