Standard library / net/netip
netip.ParseAddrPort()
Parse numeric AddrPort text and return an error for malformed input; no DNS lookup. Expected stdout: '192.0.2.7:80\n'.
Formal Syntax & Structure
go syntaxgo
func ParseAddrPort(s string) (AddrPort, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | string | Textual address or prefix to parse. |
Return Value
(AddrPort, error)
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/netip")
func main() { fmt.Println(must(netip.ParseAddrPort("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) }}