Standard library / net/netip
netip.Prefix.UnmarshalText()
Decode text into the receiver, checking the returned error. Expected stdout: '192.0.2.7/24\n'.
Formal Syntax & Structure
go syntaxgo
func (p *Prefix) 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/netip")
func main() { var v netip.Prefix; check(v.UnmarshalText([]byte("192.0.2.7/24"))); fmt.Println(v) }
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) }}