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
+14k Golang : Google Drive API upload and rename example
+9k Golang : Capture text return from exec function example
+8.4k Golang : Convert word to its plural form example
+14.3k Golang : Get uploaded file name or access uploaded files
+6.9k Golang : Decode XML data from RSS feed
+6.3k Golang : Selection sort example
+18.4k Golang : Read binary file into memory
+7.5k Golang : Detect sample rate, channels or latency with PortAudio
+17.6k Golang : Upload/Receive file progress indicator
+35.3k Golang : Strip slashes from string example
+5.7k Golang : Error handling methods
+12.2k Golang : Simple client-server HMAC authentication without SSL example