Golang go/doc.Examples() function example
package go/doc
Examples returns the examples found in the files, sorted by Name field. The Order fields record the order in which the examples were encountered.
Playable Examples must be in a package whose name ends in "_test". An Example is "playable" (the Play field is non-nil) in either of these circumstances:
- The example function is self-contained: the function references only identifiers from other packages (or predeclared identifiers, such as "int") and the test file does not include a dot import.
- The entire test file is the example: the file contains exactly one example function, zero test or benchmark functions, and at least one top-level function, type, variable, or constant declaration other than the example function.
Golang go/doc.Examples() function usage example
var files []*ast.File
var examples []*doc.Example
for _, e := range doc.Examples(files...) {
name := stripExampleSuffix(e.Name)
if name == "" || globals[name] {
examples = append(examples, e)
} else if c.Verbose {
log.Printf("skipping example 'Example%s' because '%s' is not a known function or type", e.Name, e.Name)
}
}
Reference :
Advertisement
Something interesting
Tutorials
+7.8k Golang : Regular Expression find string example
+18.6k Golang : Find IP address from string
+7.5k Golang : Handling Yes No Quit query input
+7.8k Golang : Example of how to detect which type of script a word belongs to
+16.3k Golang :Trim white spaces from a string
+19k Golang : Padding data for encryption and un-padding data for decryption
+13.8k Generate salted password with OpenSSL example
+15.2k Golang : How to add color to string?
+6.1k Fix ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)
+10.6k Golang : Allow Cross-Origin Resource Sharing request
+4.7k Fix Google Analytics Redundant Hostnames problem
+7.3k Golang : Fixing Gorilla mux http.FileServer() 404 problem