start Golang with Beego and Build by Bazel

前置条件:安装 java、go、xcode、bazel、vscode、beego,安装过程略。

笔者环境如下:

Microsoft Windows [版本 10.0.17134.228]
- - -
go version go1.11.1 windows/amd64
- - -
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32
- - -
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
- - -
bazel version
Build label: 0.19.0
Build target: bazel-out/x64_windows-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Oct 29 14:35:48 2018 (1540823748)
Build timestamp: 1540823748
Build timestamp as int: 1540823748
- - -
Visual Studio Code - Insiders
版本: 1.30.0-insider (system setup)
提交: 5fc60ec67950234cdf82ea455013617adf00e7b6
日期: 2018-11-14T06:20:26.830Z
Electron: 2.0.12
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
架构: x64

首先,我们拿 Beego 来练手,先在本地新建一个 Begoo 项目跑起来:

git clone -b bazel https://gitlab.com/higkoohk/Mash && cd Mash
govendor init
govendor add +external
cp -rfv conf views tests/

beego demo
在Gitlab上配置CI/CD后提交代码触发自动构建,成功:
higkoo MashMash 作业 #121015045
接下来体验一下 Bazel 的效果:

#使用Gazelle自动生成Bazel配置文件
go get -u github.com/bazelbuild/bazel-gazelle/cmd/gazelle
gazelle -go_prefix gitlab.com/higkoohk/Mash
#或者用Bazel来驱动Gazelle来生成编译配置
cat << _EOF > BUILD.bazel
load("@bazel_gazelle//:def.bzl", "gazelle")
# gazelle:prefix gitlab.com/higkoohk/Mash
gazelle(name = "gazelle")
_EOF
bazel run //:gazelle

生成 gitlab.com/higkoohk/Mash/BUILD.bazel 文件如下:

load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
    name = "go_default_library",
    srcs = ["main.go"],
    importpath = "gitlab.com/higkoohk/Mash",
    visibility = ["//visibility:private"],
    deps = [
        "//vendor/github.com/astaxie/beego:go_default_library",
        "//routers:go_default_library",
    ],
)

go_binary(
    name = "Mash",
    embed = [":go_default_library"],
    visibility = ["//visibility:public"],
)

成功开启build //...模式: Bazel Build 编译过程
附加信息:
苹果系统开启vscode之go的debug功能需要xcode的命令行工具,使用 xcode-select --install 可能由于网络原因执行失败:
xcode-select --install 安装失败
可以通过苹果的开发者网站 https://developer.apple.com/download/more/ 下载,手动安装:
苹果开发者网络下载安装包

转载于:https://my.oschina.net/higkoo/blog/2414043

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值