$ go version
go version devel +5de90d33c8 Thu Jul 2 22:08:11 2020 +0000 linux/amd64
Running go doc rand, as expected, gives the documentation for crypto/rand, as it finds that one before math/rand:
package rand // import "crypto/rand"
Package rand implements a cryptographically secure random number generator.
var Reader io.Reader
func Int(rand io.Reader, max *big.Int) (n *big.Int, err error)
func Prime(rand io.Reader, bits int) (p *big.Int, err error)
Running go doc rand.rand, however, gives the documentation for math/rand.Rand, as it uses the lack of the symbol in crypto/rand to know that that's not the right package. So far so good:
package rand // import "math/rand"
type Rand struct {
// Has unexported fields.
}
A Rand is a source of random numbers.
func New(src Source) *Rand
func (r *Rand) ExpFloat64() float64
func (r *Rand) Float32() float32
func (r *Rand) Float64() float64
func (r *Rand) Int() int
func (r *Rand) Int31() int32
func (r *Rand) Int31n(n int32) int32
func (r *Rand) Int63() int64
func (r *Rand) Int63n(n int64) int64
func (r *Rand) Intn(n int) int
func (r *Rand) NormFloat64() float64
func (r *Rand) Perm(n int) []int
func (r *Rand) Read(p []byte) (n int, err error)
func (r *Rand) Seed(seed int64)
func (r *Rand) Shuffle(n int, swap func(i, j int))
func (r *Rand) Uint32() uint32
func (r *Rand) Uint64() uint64
However, running go doc rand.rand.int fails:
doc: symbol rand is not a type in package rand installed in "crypto/rand"
exit status 1
It seems like it doesn't actually search past the first package if there's a method specified. Manually specifying the package, such as go doc math/rand.rand.int, works as expected.
Running
go doc rand, as expected, gives the documentation forcrypto/rand, as it finds that one beforemath/rand:Running
go doc rand.rand, however, gives the documentation formath/rand.Rand, as it uses the lack of the symbol incrypto/randto know that that's not the right package. So far so good:However, running
go doc rand.rand.intfails:It seems like it doesn't actually search past the first package if there's a method specified. Manually specifying the package, such as
go doc math/rand.rand.int, works as expected.