I am currently writing ExampleFuncs
in my Go test scripts. For example:
package hello
import "testing"
func ExampleGetSymbol() {
data := GetSymbol("AAPL")
fmt.Println(len(data.Data))
// Output: 21
}
Now, this gives me two benefits:
- This example is executed when I am running
go test
and - It appears in the godoc documentation under
func GetSymbol
One thing bothers me and I am wondering if there is anything I should do about it. For the user that's trying to learn from this example, the line
data := GetSymbol("AAPL")
should actually be
data := hello.GetSymbol("AAPL")
but since the test is in the same scope as the package, I cannot use it like this.
So I guess the distilled version of my question would be:
Is there a way to allow package.field
notation inside the package scope?
Thanks in advance