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
+14.8k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+20.9k Golang : Underscore or snake_case to camel case example
+5.2k Golang : Issue HTTP commands to server and port example
+32.2k Golang : Convert []string to []byte examples
+19.9k Golang : Count JSON objects and convert to slice/array
+5.2k Golang : Print instead of building pyramids
+11.6k Swift : Convert (cast) Float to String
+5.3k Golang : How to deal with configuration data?
+18.6k Golang : Get download file size
+6.7k Golang : Output or print out JSON stream/encoded data
+13.1k Golang : Convert(cast) uintptr to string example
+17.2k Golang : Find file size(disk usage) with filepath.Walk