October 2015
Beginner to intermediate
400 pages
14h 44m
English
Example Functions
The third kind of function treated specially by go test is an
example function, one whose name starts with Example. It has
neither parameters nor results. Here’s an example function for
IsPalindrome:
func ExampleIsPalindrome() {
fmt.Println(IsPalindrome("A man, a plan, a canal: Panama"))
fmt.Println(IsPalindrome("palindrome"))
// Output:
// true
// false
}
Figure 11.4.
An interactive example of strings.Join in godoc.
Example functions serve three purposes. The primary one is documentation: a good example can be a more succinct or intuitive way to convey the behavior of a library function ...
Read now
Unlock full access