有没有办法稍后再导入golang?

I'm writing a small go program. I expect it to be run on different OSes, so I was hoping to use go run rather than including the compiled file. The problem is it uses a package from outside the standard library. I don't want to rely on people having the package. I can get the package using

package main

import "os/exec"

func main() {
    _ := exec.Command("go", "get","github.com/user/library").Run()
}

But by then it's too late to import it. I can see three solutions.

  1. Make a wrapper script.

  2. Cross-compile

  3. Get the user to do it

But I'd really like to install it and then import, is there any way to do so?

Just host your code on github or somewhere else. Then the people who want to run the program can use go install "example.com" to get a binary.

If you dont want to host your code, you can instruct them to put it in their GOPATH/src/ and use go install yourprojectsname.