go install method

This commit is contained in:
alessio 2016-08-03 18:49:17 +02:00
parent d2753cb9b6
commit e98dd76f9b
1 changed files with 13 additions and 4 deletions

View File

@ -5,7 +5,6 @@ import (
"os/exec" "os/exec"
"os" "os"
"bytes" "bytes"
"fmt"
) )
type Project struct { type Project struct {
@ -31,20 +30,30 @@ func (p *Project) GoBuild() error{
// create bin dir // create bin dir
if _, err := os.Stat(path + "bin"); err != nil { if _, err := os.Stat(path + "bin"); err != nil {
if err = os.Mkdir(path + "bin", 0777); err != nil{ if err = os.Mkdir(path + "bin", 0777); err != nil{
fmt.Println(err) return err
} }
} }
build := exec.Command("go", "build", path + p.Main) build := exec.Command("go", "build", path + p.Main)
build.Dir = path + "bin" build.Dir = path + "bin"
build.Stdout = &out build.Stdout = &out
if err := build.Run(); err != nil { if err := build.Run(); err != nil {
fmt.Println(err)
return err return err
} }
return nil return nil
} }
func GoInstall() error{ func (p *Project) GoInstall() error{
var out bytes.Buffer
base, _ := os.Getwd()
path := base
build := exec.Command("go", "install")
build.Dir = path
build.Stdout = &out
if err := build.Run(); err != nil {
return err
}
return nil return nil
} }