Skip to content

Commit

Permalink
Add Separator variable #5
Browse files Browse the repository at this point in the history
  • Loading branch information
System-Glitch committed Aug 29, 2022
1 parent 71df4a7 commit 8254fd2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"goyave.dev/goyave/v4/validation"
)

// Separator the separator used when parsing the query
var Separator = "||"

func init() {
validation.AddRule("filter", &validation.RuleDefinition{
Function: validateFilter,
Expand Down Expand Up @@ -114,7 +117,7 @@ func ParseFilter(filter string) (*Filter, error) {
f := filter
op := ""

index := strings.Index(f, "||")
index := strings.Index(f, Separator)
if index == -1 {
return nil, fmt.Errorf("Missing operator")
}
Expand All @@ -124,7 +127,7 @@ func ParseFilter(filter string) (*Filter, error) {
}
f = f[index+2:]

index = strings.Index(f, "||")
index = strings.Index(f, Separator)
if index == -1 {
index = len(f)
}
Expand Down Expand Up @@ -189,7 +192,7 @@ func ParseSort(sort string) (*Sort, error) {
// ParseJoin parse a string in format "relation||field1,field2,..." and return
// a Join struct.
func ParseJoin(join string) (*Join, error) {
separatorIndex := strings.Index(join, "||")
separatorIndex := strings.Index(join, Separator)
if separatorIndex == -1 {
separatorIndex = len(join)
}
Expand Down

0 comments on commit 8254fd2

Please sign in to comment.