Standard library / net/netip
netip.Prefix.Contains()
Test containment in the same address family; zoned addresses do not match. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func (p Prefix) Contains(ip Addr) boolParameters & Attributes
| Name | Type | Description |
|---|---|---|
| ip | Addr | IP address to use or test. |
Return Value
bool
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/netip")
func main() { fmt.Println(netip.MustParsePrefix("192.0.2.7/24").Contains(netip.MustParseAddr("192.0.2.99")))}
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}