转到:无法运行非主程序包?

I always get error

cannot run non-main package

Its just a code from github.

the program that you link to doesn't contain a main function (or more properly in GO terms, a package named main, that itself contains a function called main which is the entry point of the program (well before main there can also be a function called init that is used to initialize data. take a look at the flag package ))

The fastrand repository that you linked to is supposed to be run as a library from other go programs that are going to use the functions it exposes. For example to get an integer from 0 to n [0, n) using this library you can use this toy program.

package main

import (
        "fmt"
        "github.com/NebulousLabs/fastrand"
)

func main() {
        //prints a random int [0,10) using fastrand
        fmt.Printf("random int:%d
", fastrand.Intn(10))
}

put that in a directory under your GOPATH, (let's say you name it foo.go) run

go get github.com/NebulousLabs/fastrand; 
go build foo.go; 
./foo;