MCPcopy Create free account
hub / github.com/cel-expr/cel-go / Network

Function Network

ext/network.go:133–149  ·  view source on GitHub ↗

Network returns a cel.EnvOption to configure extended functions for network address parsing, inspection, and CIDR range manipulation. Note: This library defines global functions `ip`, `cidr`, `isIP`, `isCIDR` and `ip.isCanonical`. If you are currently using variables named `ip` or `cidr`, these fun

(opts ...NetworkOption)

Source from the content-addressed store, hash-verified

131// cidr('192.168.1.5/24').masked() == cidr('192.168.1.0/24')
132// cidr('192.168.1.0/24').prefixLength() == 24
133func Network(opts ...NetworkOption) cel.EnvOption {
134 lib := &networkLib{version: Version1}
135 for _, o := range opts {
136 lib = o(lib)
137 }
138 return func(e *cel.Env) (*cel.Env, error) {
139 // Install the library (Types and Functions)
140 e, err := cel.Lib(lib)(e)
141 if err != nil {
142 return nil, err
143 }
144
145 // Install the Adapter (Wrapping the existing one)
146 adapter := &networkAdapter{Adapter: e.CELTypeAdapter()}
147 return cel.CustomTypeAdapter(adapter)(e)
148 }
149}
150
151// NetworkOption declares a functional operator for configuring the Network library behavior.
152type NetworkOption func(*networkLib) *networkLib

Callers 4

TestNetwork_SuccessFunction · 0.85
testCostFunction · 0.85

Calls 3

LibFunction · 0.92
CustomTypeAdapterFunction · 0.92
CELTypeAdapterMethod · 0.80

Tested by 4

TestNetwork_SuccessFunction · 0.68
testCostFunction · 0.68