Standard library / net/netip
netip.AddrPortFrom()
Combine an address with a numeric port without resolving a name. Expected stdout: '192.0.2.7:80\n'.
Formal Syntax & Structure
go syntaxgo
func AddrPortFrom(ip Addr, port uint16) AddrPortParameters & Attributes
| Name | Type | Description |
|---|---|---|
| ip | Addr | IP address to use or test. |
| port | uint16 | Port number or textual port according to the signature. |
Return Value
AddrPort
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/netip")
func main() { fmt.Println(netip.AddrPortFrom(netip.MustParseAddr("192.0.2.7"), 80)) }
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) }}