Standard library / net
net.ResolveTCPAddr()
Resolve a numeric endpoint into a typed address. Names can trigger DNS; this example uses numeric input. Expected stdout: '192.0.2.7:80\n'.
Formal Syntax & Structure
go syntaxgo
func ResolveTCPAddr(network, address string) (*TCPAddr, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| network | string | Network family such as tcp4 or udp4. |
| address | string | Network address including port when required. |
Return Value
(*TCPAddr, error)
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net")
func main() { fmt.Println(must(net.ResolveTCPAddr("tcp4", "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) }}