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 :
Advertisement
Something interesting
Tutorials
+5k Golang : micron to centimeter example
+12.5k Golang : HTTP response JSON encoded data
+26.4k Golang : Get executable name behind process ID example
+7k Web : How to see your website from different countries?
+6.2k Golang : Get missing location after unmarshal binary and gob decode time.
+6.7k Golang : When to use make or new?
+12.6k Golang : flag provided but not defined error
+9.4k Golang : Find the length of big.Int variable example
+7.5k Golang : Rot13 and Rot5 algorithms example
+23.1k Golang : Randomly pick an item from a slice/array example
+6.8k Unix/Linux : How to fix CentOS yum duplicate glibc or device-mapper-libs dependency error?