Standard library / net
net.IP.UnmarshalText()
Decode address text into an IP variable; malformed nonempty text returns an error. Expected stdout: '192.0.2.7\n'.
Formal Syntax & Structure
go syntaxgo
func (ip *IP) UnmarshalText(text []byte) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| text | []byte | Text encoding of the address, endpoint or prefix. |
Return Value
error
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net")
func main() { var ip net.IP; check(ip.UnmarshalText([]byte("192.0.2.7"))); fmt.Println(ip) }
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) }}