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 Golang : Normalize email to prevent multiple signups example
+7.4k Golang : Example of custom handler for Gorilla's Path usage.
+9.4k Golang : Generate EAN barcode
+7.5k Golang : How to stop user from directly running an executable file?
+13.9k Golang : How to determine if a year is leap year?
+46.5k Golang : Marshal and unmarshal json.RawMessage struct example
+7.9k Golang : Get today's weekday name and calculate target day distance example
+5.2k Golang : Convert lines of string into list for delete and insert operation
+12.3k Golang : 2 dimensional array example
+15.4k Golang : invalid character ',' looking for beginning of value
+8.7k Golang : How to join strings?
+21.1k Golang : For loop continue,break and range