Standard library / net/netip
netip.Prefix.MarshalText()
Produce text suitable for text-based serialization. Expected stdout: '192.0.2.7/24\n'.
Formal Syntax & Structure
go syntaxgo
func (p Prefix) MarshalText() ([]byte, error)Return Value
([]byte, error)
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/netip")
func main() { fmt.Println(string(must(netip.MustParsePrefix("192.0.2.7/24").MarshalText()))) }
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) }}