Standard library / net/netip

netip.Addr.Compare()

Compare using address ordering: -1, 0 or 1. Expected stdout: '-1\n'.

Formal Syntax & Structure

go syntaxgo
func (ip Addr) Compare(ip2 Addr) int

Parameters & Attributes

NameTypeDescription
ip2AddrAddress 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.MustParseAddr("192.0.2.7").Compare(netip.MustParseAddr("192.0.2.8"))) }
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)  }}
Go Reference