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
+4.6k Linux : sudo yum updates not working
+16.3k Golang : How to extract links from web page ?
+28.8k Golang : Detect (OS) Operating System
+5.8k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+8.5k Golang : How to check if input string is a word?
+9.5k Golang : Detect Pascal, Kebab, Screaming Snake and Camel cases
+9.2k Golang : Generate Codabar
+6.1k Golang : Debug with Godebug
+12.3k Golang : Flush and close file created by os.Create and bufio.NewWriter example
+18.5k Golang : Example for RSA package functions
+6k Linux/MacOSX : Search for files by filename and extension with find command
+43.3k Golang : Convert []byte to image