Standard library / net
net.SplitHostPort()
Split an endpoint into host and port; IPv6 literals require brackets. Expected stdout: '2001:db8::1 443\n'.
Formal Syntax & Structure
go syntaxgo
func SplitHostPort(hostport string) (host, port string, err error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| hostport | string | Combined host and port, with IPv6 in brackets. |
Return Value
(host, port string, err error)
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net")
func main() { h, p, e := net.SplitHostPort("[2001:db8::1]:443"); check(e); fmt.Println(h, p) }
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) }}