MCPcopy
hub / github.com/expr-lang/expr / DefaultEnv

Function DefaultEnv

test/coredns/coredns.go:9–39  ·  view source on GitHub ↗
(ctx context.Context, state *Request)

Source from the content-addressed store, hash-verified

7)
8
9func DefaultEnv(ctx context.Context, state *Request) map[string]any {
10 return map[string]any{
11 "incidr": func(ipStr, cidrStr string) (bool, error) {
12 ip := net.ParseIP(ipStr)
13 if ip == nil {
14 return false, errors.New("first argument is not an IP address")
15 }
16 _, cidr, err := net.ParseCIDR(cidrStr)
17 if err != nil {
18 return false, err
19 }
20 return cidr.Contains(ip), nil
21 },
22 "metadata": func(label string) string {
23 return ""
24 },
25 "type": state.Type,
26 "name": state.Name,
27 "class": state.Class,
28 "proto": state.Proto,
29 "size": state.Len,
30 "client_ip": state.IP,
31 "port": state.Port,
32 "id": func() int { return int(state.Req.Id) },
33 "opcode": func() int { return state.Req.Opcode },
34 "do": state.Do,
35 "bufsize": state.Size,
36 "server_ip": state.LocalIP,
37 "server_port": state.LocalPort,
38 }
39}
40
41type Request struct {
42 Req *Msg

Callers 1

TestCoreDNSFunction · 0.92

Calls 1

ContainsMethod · 0.45

Tested by 1

TestCoreDNSFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…