mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 09:05:55 +00:00
29 lines
540 B
Go
29 lines
540 B
Go
package build
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"io/ioutil"
|
|
"os"
|
|
"os/exec"
|
|
)
|
|
|
|
func Binary(pkg, goos, goarch string) (io.Reader, error) {
|
|
binFile, err := ioutil.TempFile("", "pilosactl")
|
|
if err != nil {
|
|
return nil, fmt.Errorf("build binary: %v", err)
|
|
}
|
|
com := exec.Command("go", "build", "-o", binFile.Name(), pkg)
|
|
com.Env = append([]string{"GOOS=" + goos, "GOARCH=" + goarch}, os.Environ()...)
|
|
|
|
err = com.Run()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
f, err := os.Open(binFile.Name())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return f, nil
|
|
}
|