Jelajahi Sumber

Add HTTP and filter helper functions for collections

Signed-off-by: Niko Kovacevic <nikovacevic@gmail.com>
Signed-off-by: Matt Bolt <mbolt35@gmail.com>
Niko Kovacevic 2 tahun lalu
induk
melakukan
cb707cff54
2 mengubah file dengan 20 tambahan dan 0 penghapusan
  1. 9 0
      core/pkg/filter/ast/ops.go
  2. 11 0
      core/pkg/protocol/http.go

+ 9 - 0
core/pkg/filter/ast/ops.go

@@ -191,3 +191,12 @@ type ContainsSuffixOp struct {
 func (_ *ContainsSuffixOp) Op() FilterOp {
 	return FilterOpContainsSuffix
 }
+
+func Not(fn FilterNode) FilterNode {
+	return &NotOp{Operand: fn}
+}
+
+func IsVoid(fn FilterNode) bool {
+	_, ok := fn.(*VoidOp)
+	return ok
+}

+ 11 - 0
core/pkg/protocol/http.go

@@ -31,6 +31,17 @@ func (hp HTTPProtocol) BadRequest(message string) HTTPError {
 	}
 }
 
+// UnprocessableEntity creates an UnprocessableEntity HTTPError
+func (hp HTTPProtocol) UnprocessableEntity(message string) HTTPError {
+	if message == "" {
+		message = "Unprocessable Entity"
+	}
+	return HTTPError{
+		StatusCode: http.StatusUnprocessableEntity,
+		Body:       message,
+	}
+}
+
 // InternalServerError creates an InternalServerError HTTPError
 func (hp HTTPProtocol) InternalServerError(message string) HTTPError {
 	if message == "" {