-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
querystring_filter.go
60 lines (49 loc) · 1.77 KB
/
querystring_filter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Code generated by __generator__/interpreter.go at once
package builtin
import (
"bytes"
"github.com/ysugimoto/falco/interpreter/context"
"github.com/ysugimoto/falco/interpreter/function/errors"
"github.com/ysugimoto/falco/interpreter/function/shared"
"github.com/ysugimoto/falco/interpreter/value"
)
const Querystring_filter_Name = "querystring.filter"
var Querystring_filter_ArgumentTypes = []value.Type{value.StringType, value.StringType}
func Querystring_filter_Validate(args []value.Value) error {
if len(args) != 2 {
return errors.ArgumentNotEnough(Querystring_filter_Name, 2, args)
}
for i := range args {
if args[i].Type() != Querystring_filter_ArgumentTypes[i] {
return errors.TypeMismatch(Querystring_filter_Name, i+1, Querystring_filter_ArgumentTypes[i], args[i].Type())
}
}
return nil
}
// Fastly built-in function implementation of querystring.filter
// Arguments may be:
// - STRING, STRING
// Reference: https://developer.fastly.com/reference/vcl/functions/query-string/querystring-filter/
func Querystring_filter(ctx *context.Context, args ...value.Value) (value.Value, error) {
// Argument validations
if err := Querystring_filter_Validate(args); err != nil {
return value.Null, err
}
v := value.Unwrap[*value.String](args[0])
names := value.Unwrap[*value.String](args[1])
query, err := shared.ParseQuery(v.Value)
if err != nil {
return value.Null, errors.New(
Querystring_filter_Name, "Failed to parse query: %s, error: %s", v.Value, err.Error(),
)
}
filterMap := make(map[string]struct{})
for _, f := range bytes.Split([]byte(names.Value), Querystring_filtersep_Sign) {
filterMap[string(f)] = struct{}{}
}
query.Filter(func(name string) bool {
_, ok := filterMap[name]
return !ok
})
return &value.String{Value: query.String()}, nil
}