MCPcopy
hub / github.com/lxc/incus / Example_complementRanges

Function Example_complementRanges

internal/server/network/network_utils_test.go:142–182  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

140}
141
142func Example_complementRanges() {
143 _, ipnet, err := net.ParseCIDR("10.1.1.0/24")
144 if err != nil {
145 fmt.Printf("Err: %v\n", err)
146 return
147 }
148
149 ranges := [][]*iprange.Range{
150 {
151 {Start: net.ParseIP("10.1.1.1"), End: net.ParseIP("10.1.1.10")},
152 },
153 {
154 {Start: net.ParseIP("10.1.1.10"), End: net.ParseIP("10.1.1.100")},
155 {Start: net.ParseIP("10.1.1.200"), End: net.ParseIP("10.1.1.230")},
156 },
157 {
158 {Start: net.ParseIP("10.1.1.10"), End: net.ParseIP("10.1.1.20")},
159 {Start: net.ParseIP("10.1.1.15"), End: net.ParseIP("10.1.1.25")},
160 },
161 }
162
163 for idx, r := range ranges {
164 result, err := complementRanges(r, ipnet)
165 if err != nil {
166 fmt.Printf("Err: %v\n", err)
167 return
168 }
169
170 parts := make([]string, len(result))
171 for i, r := range result {
172 parts[i] = fmt.Sprintf("%s-%s", r.Start.String(), r.End.String())
173 }
174
175 fmt.Printf("Range%d: %s\n", idx+1, strings.Join(parts, ", "))
176 }
177
178 // Output:
179 // Range1: 10.1.1.11-10.1.1.254
180 // Range2: 10.1.1.1-10.1.1.9, 10.1.1.101-10.1.1.199, 10.1.1.231-10.1.1.254
181 // Range3: 10.1.1.1-10.1.1.9, 10.1.1.26-10.1.1.254
182}

Callers

nothing calls this directly

Calls 2

complementRangesFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…