部署
编译打包
windows平台打包linux可执行文件
package main
import (
"fmt"
"os"
"os/exec"
)
//filepath: 要编译的文件的路径
func build(filepath string){
_ = os.Setenv("CGO_ENABLED", "0")
_ = os.Setenv("GOARCH", "amd64")
_ = os.Setenv("GOOS", "linux")
arg := []string{"build", filepath}
if err := exec.Command("go", arg...).Run(); err!=nil {
fmt.Println("编译失败:", err)
} else{
fmt.Println("编译成功")
}
}
func main() {
build(`D:\WorkProject\go\src\beego_first\main.go`)
}
go 编译之后是二进制文件,beego:打包需要自行copy > (views,static,conf) 几个文件夹到部署应用目录下