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
+6.9k Nginx : Password protect a directory/folder
+6.5k Golang : Handling image beyond OpenCV video capture boundary
+17.9k Golang : Simple client server example
+15.2k Golang : How to check if IP address is in range
+11.8k Golang : Verify Linux user password again before executing a program example
+6.5k Golang : Calculate diameter, circumference, area, sphere surface and volume
+7.6k SSL : How to check if current certificate is sha1 or sha2 from command line
+17.8k Golang : Iterate linked list example
+14.6k Golang : GUI with Qt and OpenCV to capture image from camera
+6k Fontello : How to load and use fonts?
+43.5k Golang : Get hardware information such as disk, memory and CPU usage
+16.8k Golang : Get own process identifier