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)
| 128 | // cidr('192.168.1.5/24').masked() == cidr('192.168.1.0/24') |
| 129 | // cidr('192.168.1.0/24').prefixLength() == 24 |
| 130 | func 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. |
| 149 | type NetworkOption func(*networkLib) *networkLib |