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
+7.1k Golang : Get Alexa ranking data example
+9.2k Golang : Create and shuffle deck of cards example
+16.5k Golang : Execute terminal command to remote machine example
+6k Javascript : Get operating system and browser information
+12.2k Golang : Simple client-server HMAC authentication without SSL example
+18.5k Golang : Send email with attachment
+12.7k Golang : zlib compress file example
+4.6k Mac OSX : Get disk partitions' size, type and name
+12.6k Golang : Get absolute path to binary for os.Exec function with exec.LookPath
+14.6k Golang : GUI with Qt and OpenCV to capture image from camera
+28.8k Golang : Detect (OS) Operating System
+22.7k Golang : Set and Get HTTP request headers example