mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-10-13 19:13:43 +08:00
chore: upgrade coredns version (#550)
This commit is contained in:
1069
vendor/github.com/expr-lang/expr/builtin/builtin.go
generated
vendored
Normal file
1069
vendor/github.com/expr-lang/expr/builtin/builtin.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
23
vendor/github.com/expr-lang/expr/builtin/function.go
generated
vendored
Normal file
23
vendor/github.com/expr-lang/expr/builtin/function.go
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
package builtin
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type Function struct {
|
||||
Name string
|
||||
Fast func(arg any) any
|
||||
Func func(args ...any) (any, error)
|
||||
Safe func(args ...any) (any, uint, error)
|
||||
Types []reflect.Type
|
||||
Validate func(args []reflect.Type) (reflect.Type, error)
|
||||
Deref func(i int, arg reflect.Type) bool
|
||||
Predicate bool
|
||||
}
|
||||
|
||||
func (f *Function) Type() reflect.Type {
|
||||
if len(f.Types) > 0 {
|
||||
return f.Types[0]
|
||||
}
|
||||
return reflect.TypeOf(f.Func)
|
||||
}
|
433
vendor/github.com/expr-lang/expr/builtin/lib.go
generated
vendored
Normal file
433
vendor/github.com/expr-lang/expr/builtin/lib.go
generated
vendored
Normal file
@@ -0,0 +1,433 @@
|
||||
package builtin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/expr-lang/expr/internal/deref"
|
||||
"github.com/expr-lang/expr/vm/runtime"
|
||||
)
|
||||
|
||||
func Len(x any) any {
|
||||
v := reflect.ValueOf(x)
|
||||
switch v.Kind() {
|
||||
case reflect.Array, reflect.Slice, reflect.Map:
|
||||
return v.Len()
|
||||
case reflect.String:
|
||||
return utf8.RuneCountInString(v.String())
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid argument for len (type %T)", x))
|
||||
}
|
||||
}
|
||||
|
||||
func Type(arg any) any {
|
||||
if arg == nil {
|
||||
return "nil"
|
||||
}
|
||||
v := reflect.ValueOf(arg)
|
||||
if v.Type().Name() != "" && v.Type().PkgPath() != "" {
|
||||
return fmt.Sprintf("%s.%s", v.Type().PkgPath(), v.Type().Name())
|
||||
}
|
||||
switch v.Type().Kind() {
|
||||
case reflect.Invalid:
|
||||
return "invalid"
|
||||
case reflect.Bool:
|
||||
return "bool"
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return "int"
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
return "uint"
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return "float"
|
||||
case reflect.String:
|
||||
return "string"
|
||||
case reflect.Array, reflect.Slice:
|
||||
return "array"
|
||||
case reflect.Map:
|
||||
return "map"
|
||||
case reflect.Func:
|
||||
return "func"
|
||||
case reflect.Struct:
|
||||
return "struct"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
func Abs(x any) any {
|
||||
switch x := x.(type) {
|
||||
case float32:
|
||||
if x < 0 {
|
||||
return -x
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
case float64:
|
||||
if x < 0 {
|
||||
return -x
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
case int:
|
||||
if x < 0 {
|
||||
return -x
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
case int8:
|
||||
if x < 0 {
|
||||
return -x
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
case int16:
|
||||
if x < 0 {
|
||||
return -x
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
case int32:
|
||||
if x < 0 {
|
||||
return -x
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
case int64:
|
||||
if x < 0 {
|
||||
return -x
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
case uint:
|
||||
if x < 0 {
|
||||
return -x
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
case uint8:
|
||||
if x < 0 {
|
||||
return -x
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
case uint16:
|
||||
if x < 0 {
|
||||
return -x
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
case uint32:
|
||||
if x < 0 {
|
||||
return -x
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
case uint64:
|
||||
if x < 0 {
|
||||
return -x
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
}
|
||||
panic(fmt.Sprintf("invalid argument for abs (type %T)", x))
|
||||
}
|
||||
|
||||
func Ceil(x any) any {
|
||||
switch x := x.(type) {
|
||||
case float32:
|
||||
return math.Ceil(float64(x))
|
||||
case float64:
|
||||
return math.Ceil(x)
|
||||
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
|
||||
return Float(x)
|
||||
}
|
||||
panic(fmt.Sprintf("invalid argument for ceil (type %T)", x))
|
||||
}
|
||||
|
||||
func Floor(x any) any {
|
||||
switch x := x.(type) {
|
||||
case float32:
|
||||
return math.Floor(float64(x))
|
||||
case float64:
|
||||
return math.Floor(x)
|
||||
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
|
||||
return Float(x)
|
||||
}
|
||||
panic(fmt.Sprintf("invalid argument for floor (type %T)", x))
|
||||
}
|
||||
|
||||
func Round(x any) any {
|
||||
switch x := x.(type) {
|
||||
case float32:
|
||||
return math.Round(float64(x))
|
||||
case float64:
|
||||
return math.Round(x)
|
||||
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
|
||||
return Float(x)
|
||||
}
|
||||
panic(fmt.Sprintf("invalid argument for round (type %T)", x))
|
||||
}
|
||||
|
||||
func Int(x any) any {
|
||||
switch x := x.(type) {
|
||||
case float32:
|
||||
return int(x)
|
||||
case float64:
|
||||
return int(x)
|
||||
case int:
|
||||
return x
|
||||
case int8:
|
||||
return int(x)
|
||||
case int16:
|
||||
return int(x)
|
||||
case int32:
|
||||
return int(x)
|
||||
case int64:
|
||||
return int(x)
|
||||
case uint:
|
||||
return int(x)
|
||||
case uint8:
|
||||
return int(x)
|
||||
case uint16:
|
||||
return int(x)
|
||||
case uint32:
|
||||
return int(x)
|
||||
case uint64:
|
||||
return int(x)
|
||||
case string:
|
||||
i, err := strconv.Atoi(x)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("invalid operation: int(%s)", x))
|
||||
}
|
||||
return i
|
||||
default:
|
||||
val := reflect.ValueOf(x)
|
||||
if val.CanConvert(integerType) {
|
||||
return val.Convert(integerType).Interface()
|
||||
}
|
||||
panic(fmt.Sprintf("invalid operation: int(%T)", x))
|
||||
}
|
||||
}
|
||||
|
||||
func Float(x any) any {
|
||||
switch x := x.(type) {
|
||||
case float32:
|
||||
return float64(x)
|
||||
case float64:
|
||||
return x
|
||||
case int:
|
||||
return float64(x)
|
||||
case int8:
|
||||
return float64(x)
|
||||
case int16:
|
||||
return float64(x)
|
||||
case int32:
|
||||
return float64(x)
|
||||
case int64:
|
||||
return float64(x)
|
||||
case uint:
|
||||
return float64(x)
|
||||
case uint8:
|
||||
return float64(x)
|
||||
case uint16:
|
||||
return float64(x)
|
||||
case uint32:
|
||||
return float64(x)
|
||||
case uint64:
|
||||
return float64(x)
|
||||
case string:
|
||||
f, err := strconv.ParseFloat(x, 64)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("invalid operation: float(%s)", x))
|
||||
}
|
||||
return f
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid operation: float(%T)", x))
|
||||
}
|
||||
}
|
||||
|
||||
func String(arg any) any {
|
||||
return fmt.Sprintf("%v", arg)
|
||||
}
|
||||
|
||||
func minMax(name string, fn func(any, any) bool, args ...any) (any, error) {
|
||||
var val any
|
||||
for _, arg := range args {
|
||||
rv := reflect.ValueOf(arg)
|
||||
switch rv.Kind() {
|
||||
case reflect.Array, reflect.Slice:
|
||||
size := rv.Len()
|
||||
for i := 0; i < size; i++ {
|
||||
elemVal, err := minMax(name, fn, rv.Index(i).Interface())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch elemVal.(type) {
|
||||
case int, int8, int16, int32, int64,
|
||||
uint, uint8, uint16, uint32, uint64,
|
||||
float32, float64:
|
||||
if elemVal != nil && (val == nil || fn(val, elemVal)) {
|
||||
val = elemVal
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid argument for %s (type %T)", name, elemVal)
|
||||
}
|
||||
|
||||
}
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
||||
reflect.Float32, reflect.Float64:
|
||||
elemVal := rv.Interface()
|
||||
if val == nil || fn(val, elemVal) {
|
||||
val = elemVal
|
||||
}
|
||||
default:
|
||||
if len(args) == 1 {
|
||||
return args[0], nil
|
||||
}
|
||||
return nil, fmt.Errorf("invalid argument for %s (type %T)", name, arg)
|
||||
}
|
||||
}
|
||||
return val, nil
|
||||
}
|
||||
|
||||
func mean(args ...any) (int, float64, error) {
|
||||
var total float64
|
||||
var count int
|
||||
|
||||
for _, arg := range args {
|
||||
rv := reflect.ValueOf(arg)
|
||||
switch rv.Kind() {
|
||||
case reflect.Array, reflect.Slice:
|
||||
size := rv.Len()
|
||||
for i := 0; i < size; i++ {
|
||||
elemCount, elemSum, err := mean(rv.Index(i).Interface())
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
total += elemSum
|
||||
count += elemCount
|
||||
}
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
total += float64(rv.Int())
|
||||
count++
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
total += float64(rv.Uint())
|
||||
count++
|
||||
case reflect.Float32, reflect.Float64:
|
||||
total += rv.Float()
|
||||
count++
|
||||
default:
|
||||
return 0, 0, fmt.Errorf("invalid argument for mean (type %T)", arg)
|
||||
}
|
||||
}
|
||||
return count, total, nil
|
||||
}
|
||||
|
||||
func median(args ...any) ([]float64, error) {
|
||||
var values []float64
|
||||
|
||||
for _, arg := range args {
|
||||
rv := reflect.ValueOf(arg)
|
||||
switch rv.Kind() {
|
||||
case reflect.Array, reflect.Slice:
|
||||
size := rv.Len()
|
||||
for i := 0; i < size; i++ {
|
||||
elems, err := median(rv.Index(i).Interface())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
values = append(values, elems...)
|
||||
}
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
values = append(values, float64(rv.Int()))
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
values = append(values, float64(rv.Uint()))
|
||||
case reflect.Float32, reflect.Float64:
|
||||
values = append(values, rv.Float())
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid argument for median (type %T)", arg)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
func flatten(arg reflect.Value) []any {
|
||||
ret := []any{}
|
||||
for i := 0; i < arg.Len(); i++ {
|
||||
v := deref.Value(arg.Index(i))
|
||||
if v.Kind() == reflect.Array || v.Kind() == reflect.Slice {
|
||||
x := flatten(v)
|
||||
ret = append(ret, x...)
|
||||
} else {
|
||||
ret = append(ret, v.Interface())
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func get(params ...any) (out any, err error) {
|
||||
from := params[0]
|
||||
i := params[1]
|
||||
v := reflect.ValueOf(from)
|
||||
|
||||
if v.Kind() == reflect.Invalid {
|
||||
panic(fmt.Sprintf("cannot fetch %v from %T", i, from))
|
||||
}
|
||||
|
||||
// Methods can be defined on any type.
|
||||
if v.NumMethod() > 0 {
|
||||
if methodName, ok := i.(string); ok {
|
||||
method := v.MethodByName(methodName)
|
||||
if method.IsValid() {
|
||||
return method.Interface(), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch v.Kind() {
|
||||
case reflect.Array, reflect.Slice, reflect.String:
|
||||
index := runtime.ToInt(i)
|
||||
l := v.Len()
|
||||
if index < 0 {
|
||||
index = l + index
|
||||
}
|
||||
if 0 <= index && index < l {
|
||||
value := v.Index(index)
|
||||
if value.IsValid() {
|
||||
return value.Interface(), nil
|
||||
}
|
||||
}
|
||||
|
||||
case reflect.Map:
|
||||
var value reflect.Value
|
||||
if i == nil {
|
||||
value = v.MapIndex(reflect.Zero(v.Type().Key()))
|
||||
} else {
|
||||
value = v.MapIndex(reflect.ValueOf(i))
|
||||
}
|
||||
if value.IsValid() {
|
||||
return value.Interface(), nil
|
||||
}
|
||||
|
||||
case reflect.Struct:
|
||||
fieldName := i.(string)
|
||||
value := v.FieldByNameFunc(func(name string) bool {
|
||||
field, _ := v.Type().FieldByName(name)
|
||||
if field.Tag.Get("expr") == fieldName {
|
||||
return true
|
||||
}
|
||||
return name == fieldName
|
||||
})
|
||||
if value.IsValid() {
|
||||
return value.Interface(), nil
|
||||
}
|
||||
}
|
||||
|
||||
// Main difference from runtime.Fetch
|
||||
// is that we return `nil` instead of panic.
|
||||
return nil, nil
|
||||
}
|
90
vendor/github.com/expr-lang/expr/builtin/utils.go
generated
vendored
Normal file
90
vendor/github.com/expr-lang/expr/builtin/utils.go
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
package builtin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/expr-lang/expr/internal/deref"
|
||||
)
|
||||
|
||||
var (
|
||||
anyType = reflect.TypeOf(new(any)).Elem()
|
||||
integerType = reflect.TypeOf(0)
|
||||
floatType = reflect.TypeOf(float64(0))
|
||||
arrayType = reflect.TypeOf([]any{})
|
||||
mapType = reflect.TypeOf(map[any]any{})
|
||||
timeType = reflect.TypeOf(new(time.Time)).Elem()
|
||||
locationType = reflect.TypeOf(new(time.Location))
|
||||
)
|
||||
|
||||
func kind(t reflect.Type) reflect.Kind {
|
||||
if t == nil {
|
||||
return reflect.Invalid
|
||||
}
|
||||
t = deref.Type(t)
|
||||
return t.Kind()
|
||||
}
|
||||
|
||||
func types(types ...any) []reflect.Type {
|
||||
ts := make([]reflect.Type, len(types))
|
||||
for i, t := range types {
|
||||
t := reflect.TypeOf(t)
|
||||
if t.Kind() == reflect.Ptr {
|
||||
t = t.Elem()
|
||||
}
|
||||
if t.Kind() != reflect.Func {
|
||||
panic("not a function")
|
||||
}
|
||||
ts[i] = t
|
||||
}
|
||||
return ts
|
||||
}
|
||||
|
||||
func toInt(val any) (int, error) {
|
||||
switch v := val.(type) {
|
||||
case int:
|
||||
return v, nil
|
||||
case int8:
|
||||
return int(v), nil
|
||||
case int16:
|
||||
return int(v), nil
|
||||
case int32:
|
||||
return int(v), nil
|
||||
case int64:
|
||||
return int(v), nil
|
||||
case uint:
|
||||
return int(v), nil
|
||||
case uint8:
|
||||
return int(v), nil
|
||||
case uint16:
|
||||
return int(v), nil
|
||||
case uint32:
|
||||
return int(v), nil
|
||||
case uint64:
|
||||
return int(v), nil
|
||||
default:
|
||||
return 0, fmt.Errorf("cannot use %T as argument (type int)", val)
|
||||
}
|
||||
}
|
||||
|
||||
func bitFunc(name string, fn func(x, y int) (any, error)) *Function {
|
||||
return &Function{
|
||||
Name: name,
|
||||
Func: func(args ...any) (any, error) {
|
||||
if len(args) != 2 {
|
||||
return nil, fmt.Errorf("invalid number of arguments for %s (expected 2, got %d)", name, len(args))
|
||||
}
|
||||
x, err := toInt(args[0])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%v to call %s", err, name)
|
||||
}
|
||||
y, err := toInt(args[1])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%v to call %s", err, name)
|
||||
}
|
||||
return fn(x, y)
|
||||
},
|
||||
Types: types(new(func(int, int) int)),
|
||||
}
|
||||
}
|
38
vendor/github.com/expr-lang/expr/builtin/validation.go
generated
vendored
Normal file
38
vendor/github.com/expr-lang/expr/builtin/validation.go
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
package builtin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/expr-lang/expr/internal/deref"
|
||||
)
|
||||
|
||||
func validateAggregateFunc(name string, args []reflect.Type) (reflect.Type, error) {
|
||||
switch len(args) {
|
||||
case 0:
|
||||
return anyType, fmt.Errorf("not enough arguments to call %s", name)
|
||||
default:
|
||||
for _, arg := range args {
|
||||
switch kind(deref.Type(arg)) {
|
||||
case reflect.Interface, reflect.Array, reflect.Slice:
|
||||
return anyType, nil
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64:
|
||||
default:
|
||||
return anyType, fmt.Errorf("invalid argument for %s (type %s)", name, arg)
|
||||
}
|
||||
}
|
||||
return args[0], nil
|
||||
}
|
||||
}
|
||||
|
||||
func validateRoundFunc(name string, args []reflect.Type) (reflect.Type, error) {
|
||||
if len(args) != 1 {
|
||||
return anyType, fmt.Errorf("invalid number of arguments (expected 1, got %d)", len(args))
|
||||
}
|
||||
switch kind(args[0]) {
|
||||
case reflect.Float32, reflect.Float64, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Interface:
|
||||
return floatType, nil
|
||||
default:
|
||||
return anyType, fmt.Errorf("invalid argument for %s (type %s)", name, args[0])
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user