Golang go/doc.ToText() function example

package go/doc

ToText prepares comment text for presentation in textual output. It wraps paragraphs of text to width or fewer Unicode code points and then prefixes each line with the indent. In preformatted sections (such as program text), it prefixes each non-blank line with preIndent.

Golang go/doc.ToText() function usage example

 package main

 import (
 "fmt"
 "go/doc"
 "bytes"
 )

 func main() {

 var buf bytes.Buffer

 comment := "// this line is a comment line"

 doc.ToText(&buf, comment, "**", "####", 30)

 fmt.Println(buf.String())

 }

Output :

**// this line is a comment line

Reference :

http://golang.org/pkg/go/doc/#ToText

Advertisement