Standard library / net

net.IP.MarshalText()

Encode the IP address as text. Expected stdout: '192.0.2.7\n'.

Formal Syntax & Structure

go syntaxgo
func (ip IP) 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")
func main() { fmt.Println(string(must(net.ParseIP("192.0.2.7").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)  }}
Go Reference