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

Function Network

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

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

Callers 3

TestNetwork_SuccessFunction · 0.85

Calls 3

LibFunction · 0.92
CustomTypeAdapterFunction · 0.92
CELTypeAdapterMethod · 0.80

Tested by 3

TestNetwork_SuccessFunction · 0.68