forked from inetaf/netaddr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
49 lines (40 loc) · 986 Bytes
/
example_test.go
File metadata and controls
49 lines (40 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2020 The Inet.Af AUTHORS. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package netaddr_test
import (
"fmt"
"inet.af/netaddr"
)
func ExampleIPSet() {
var b netaddr.IPSetBuilder
b.AddPrefix(netaddr.MustParseIPPrefix("10.0.0.0/8"))
b.RemovePrefix(netaddr.MustParseIPPrefix("10.0.0.0/16"))
b.AddRange(netaddr.IPRange{
From: netaddr.MustParseIP("fed0::0400"),
To: netaddr.MustParseIP("fed0::04ff"),
})
s := b.IPSet()
fmt.Println("Ranges:")
for _, r := range s.Ranges() {
fmt.Printf(" %s - %s\n", r.From, r.To)
}
fmt.Println("Prefixes:")
for _, p := range s.Prefixes() {
fmt.Printf(" %s\n", p)
}
// Output:
// Ranges:
// 10.1.0.0 - 10.255.255.255
// fed0::400 - fed0::4ff
// Prefixes:
// 10.1.0.0/16
// 10.2.0.0/15
// 10.4.0.0/14
// 10.8.0.0/13
// 10.16.0.0/12
// 10.32.0.0/11
// 10.64.0.0/10
// 10.128.0.0/9
// fed0::400/120
}