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
+10.1k Golang : Edge detection with Sobel method
+17.9k Golang : Simple client server example
+20.5k Golang : Pipe output from one os.Exec(shell command) to another command
+11.2k CodeIgniter : How to check if a session exist in PHP?
+5k Python : Convert(cast) bytes to string example
+9k Golang : Capture text return from exec function example
+41.9k Golang : How do I convert int to uint8?
+6.2k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+6.3k Golang : Test input string for unicode example
+14.4k Golang : Find network of an IP address
+12.9k Python : Convert IPv6 address to decimal and back to IPv6
+9k Golang : How to use Gorilla webtoolkit context package properly