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
+9.3k Golang : How to get ECDSA curve and parameters data?
+8.3k Useful methods to access blocked websites
+11.3k Golang : Intercept and process UNIX signals example
+11.3k Golang : Characters limiter example
+18.5k Golang : Write file with io.WriteString
+6.3k Golang : Test input string for unicode example
+8.8k Android Studio : Image button and button example
+8.9k Golang : What is the default port number for connecting to MySQL/MariaDB database ?
+26.8k Golang : Find files by extension
+18.7k Golang : Iterating Elements Over A List
+6.8k Get Facebook friends working in same company
+19.3k Golang : Get RGBA values of each image pixel