Skip to content

Commit 0df762e

Browse files
kevinburkebradfitz
authored andcommitted
net: add example for CIDRMask
I had trouble translating the documentation language into a subnet - e.g. whether /31 was CIDRMask(1, 31) or CIDRMask(1, 32) or CIDRMask(31, 32) so I thought I'd add a short example showing how to create the right masks. Change-Id: Ia6a6de08c5c30b6d2249b3194cced2d3c383e317 Reviewed-on: https://go-review.googlesource.com/32677 Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent fe057c1 commit 0df762e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/net/example_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package net_test
66

77
import (
8+
"fmt"
89
"io"
910
"log"
1011
"net"
@@ -34,3 +35,13 @@ func ExampleListener() {
3435
}(conn)
3536
}
3637
}
38+
39+
func ExampleCIDRMask() {
40+
// This mask corresponds to a /31 subnet
41+
fmt.Println(net.CIDRMask(31, 32))
42+
43+
// This mask corresponds to a /64 subnet for a IPv6 mask
44+
fmt.Println(net.CIDRMask(64, 128))
45+
// Output: fffffffe
46+
// ffffffffffffffff0000000000000000
47+
}

0 commit comments

Comments
 (0)