Golang go/doc.Synopsis() function examples

package go/doc

Synopsis returns a cleaned version of the first sentence in s (1st parameter). That sentence ends after the first period followed by space and not preceded by exactly one uppercase letter. The result string has no \n, \r, or \t characters and uses only single spaces between words. If s starts with any of the IllegalPrefixes, the result is the empty string.

Golang go/doc.Synopsis() function usage examples

Example 1:

 package main

 import (
 "fmt"
 "go/doc"
 )

 func main() {

 str := "This is a sample synopsis. [This line will not appear after processing]"

 synopsis := doc.Synopsis(str)

 fmt.Println(synopsis)
 }

Output :

This is a sample synopsis.

Example 2:

 var dirname string
 var m doc.Mode
 pkgName := astFile.Name.Name
 astPkg := ast.Package{
 Name: pkgName,
 Files: map[string]*ast.File{
 filename: astFile,
 },
 }
 docPkg := doc.New(&astPkg, dirname, m)
 synopsis := doc.Synopsis(docPkg.Doc)

Reference :

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

Advertisement