Standard library / net/netip
netip.AddrPort.Compare()
Order by address first and port second. Expected stdout: '-1\n'.
Formal Syntax & Structure
go syntaxgo
func (p AddrPort) Compare(p2 AddrPort) intParameters & Attributes
| Name | Type | Description |
|---|---|---|
| p2 | AddrPort | Endpoint to compare against the receiver. |
Return Value
int
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/netip")
func main() { fmt.Println(netip.MustParseAddrPort("192.0.2.7:80").Compare(netip.MustParseAddrPort("192.0.2.7:81")))}
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) }}