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
+51.4k Golang : Check if item is in slice/array
+14.5k How to automatically restart your crashed Golang server
+8.1k Golang : How To Use Panic and Recover
+18.6k Golang : Find IP address from string
+32.4k Golang : Math pow(the power of x^y) example
+8.3k Swift : Convert (cast) Character to Integer?
+4.6k Linux : sudo yum updates not working
+9.1k Golang : How to capture return values from goroutines?
+22.9k Golang : Gorilla mux routing example
+5.9k Golang : Detect variable or constant type
+6.5k Golang : Handling image beyond OpenCV video capture boundary