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

Function Network

ext/network.go:134–150  ·  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

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