Standard library / net
net.UDPAddr.AddrPort()
Convert the address into a netip endpoint; normalize mapped IPv4 explicitly when needed. Expected stdout: '192.0.2.7\n'.
Formal Syntax & Structure
go syntaxgo
func (a *UDPAddr) AddrPort() netip.AddrPortReturn Value
netip.AddrPort
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net")
func main() { fmt.Println((&net.UDPAddr{IP: net.IPv4(192, 0, 2, 7), Port: 80}).AddrPort().Addr().Unmap())}
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) }}