-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
addr_is_ipv6.go
45 lines (37 loc) · 1.32 KB
/
addr_is_ipv6.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
// Code generated by __generator__/interpreter.go at once
package builtin
import (
"net/netip"
"github.com/ysugimoto/falco/interpreter/context"
"github.com/ysugimoto/falco/interpreter/function/errors"
"github.com/ysugimoto/falco/interpreter/value"
)
const Addr_is_ipv6_Name = "addr.is_ipv6"
var Addr_is_ipv6_ArgumentTypes = []value.Type{value.IpType}
func Addr_is_ipv6_Validate(args []value.Value) error {
if len(args) != 1 {
return errors.ArgumentNotEnough(Addr_is_ipv6_Name, 1, args)
}
for i := range args {
if args[i].Type() != Addr_is_ipv6_ArgumentTypes[i] {
return errors.TypeMismatch(Addr_is_ipv6_Name, i+1, Addr_is_ipv6_ArgumentTypes[i], args[i].Type())
}
}
return nil
}
// Fastly built-in function implementation of addr.is_ipv6
// Arguments may be:
// - IP
// Reference: https://developer.fastly.com/reference/vcl/functions/miscellaneous/addr-is-ipv6/
func Addr_is_ipv6(ctx *context.Context, args ...value.Value) (value.Value, error) {
// Argument validations
if err := Addr_is_ipv6_Validate(args); err != nil {
return value.Null, err
}
ip := value.Unwrap[*value.IP](args[0])
addr, err := netip.ParseAddr(ip.Value.String())
if err != nil {
return value.Null, errors.New(Addr_is_ipv6_Name, "Failed to parse IP address %s, %s", ip.Value.String(), err)
}
return &value.Boolean{Value: addr.Is6()}, nil
}