Standard library / encoding
encoding.TextMarshaler
Interface for producing UTF-8 text. Text representation is not necessarily a complete JSON document; JSON may quote it as a string. Expected stdout: '1970-01-01T00:00:00Z\n'.
Formal Syntax & Structure
go syntaxgo
type TextMarshaler interface { MarshalText() (text []byte, err error)}Working Example
Example Snippetgo
package main
import ( "encoding" "fmt" "time")
func must(e error) { if e != nil { panic(e) }}
func main() { var x encoding.TextMarshaler = time.Unix(0, 0).UTC() b, e := x.MarshalText() must(e) fmt.Println(string(b))}