Преглед на файлове

Improve HTTPServer validation

Stan преди 18 часа
родител
ревизия
66aef10ac8
променени са 1 файла, в които са добавени 19 реда и са изтрити 0 реда
  1. 19 0
      http_server_validate.go

+ 19 - 0
http_server_validate.go

@@ -46,6 +46,25 @@ func (this *MaxLenghtValidator) Validate(value any) bool {
 	return len(v) <= this.length
 }
 
+type ExactLenghtValidator struct {
+	length int
+}
+
+func NewExactLenghtValidator(length int) *ExactLenghtValidator {
+	return &ExactLenghtValidator{
+		length: length,
+	}
+}
+
+func (this *ExactLenghtValidator) Validate(value any) bool {
+	v, ok := value.(string)
+	if !ok {
+		return false
+	}
+
+	return len(v) == this.length
+}
+
 type RegexValidator struct {
 	expression *regexp.Regexp
 }