GO 编译 打包 部署

原文链接: https://my.oschina.net/sicilycorleone/blog/1524545

 

进入到  /data/workspace_go/github.com/freewebsys/go-admin下

 

执行  bee pack -be GOOS=linux

 

自动生成 二进制  GOODS linux   GOARCH  amd64

 

自动生成 go-admin.tar.gz,  放到服务器 /root/go/pkg下面,解压,

生成 可执行文件  go-admin、static、views和conf几个文件夹,配置conf文件下的app.conf的端口号,然后   ./go-admin即可启动服务, 但SHELL终端关闭,GO服务也随之关闭,那么如何实现后台运行呢?

 

nohup  ./go-admin 即可!!!

nohup ./go-admin 1 > goadmin.out  2 > goerror.err  也可以

 

 

======----------=============

 

package main

import (
    "github.com/astaxie/beego"
    "github.com/astaxie/beego/context"
    "github.com/astaxie/beego/logs"
    "github.com/astaxie/beego/orm"
    _ "github.com/freewebsys/go-admin/routers"
    _ "github.com/go-sql-driver/mysql"
    _ "github.com/mattn/go-sqlite3"
)

func main() {

    //注册sqlite3
    // orm.RegisterDataBase("default", "sqlite3", "go-admin.db")

    orm.RegisterDriver("mysql", orm.DRMySQL) //注册驱动                                                      

 

//注册默认数据库  (test数据库提前建好)
    orm.RegisterDataBase("default", "mysql", "root:123456@/test?charset=utf8", 30, 30)

    //同步 ORM 对象和数据库
    //这时, 在你重启应用的时候, beego 便会自动帮你创建数据库表。
    orm.Debug = true

    orm.RunSyncdb("default", false, true)

    //增加拦截器。
    var filterAdmin = func(ctx *context.Context) {
        url := ctx.Input.URL()
        logs.Info("##### filter url : %s", url)
        //TODO 如果判断用户未登录。

    }
    beego.InsertFilter("/admin/*", beego.BeforeExec, filterAdmin)

    beego.Run()
}
 

转载于:https://my.oschina.net/sicilycorleone/blog/1524545

你可能感兴趣的:(GO 编译 打包 部署)