Standard library / go/doc
go/doc.Package.Synopsis()
Returns the first sentence with whitespace normalized. Expected stdout: 'First sentence.\n'.
Formal Syntax & Structure
go syntaxgo
func (p *Package) Synopsis(text string) stringParameters & Attributes
| Name | Type | Description |
|---|---|---|
| text | string | Input to the operation as described above. |
Return Value
string
Returns the first sentence with whitespace normalized.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/ast" "go/doc" "go/parser" "go/token")
func check(e error) { if e != nil { panic(e) }}func packageDoc(mode doc.Mode) *doc.Package { fs := token.NewFileSet() f, e := parser.ParseFile(fs, "demo.go", `// Package demo documents values.package demo// Answer is a number.const Answer=42// hidden is private.var hidden=1// Item describes a value.type Item struct{}// Work performs work.func Work(){}// BUG(user): fix example.`, parser.ParseComments) check(e) p, e := doc.NewFromFiles(fs, []*ast.File{f}, "example.invalid/demo", mode) check(e) return p}
func main() { p := packageDoc(0); fmt.Println(p.Synopsis("First sentence. Second sentence.")) }