背景

Go程序运行时打印git提交信息编译信息
Golang编译信息注入程序
当在debug的过程中,我们需要明确当前运行的go程序是什么版本
不要浪费时间在确认版本的问题上
在go build编译的时候是可以注入外部参数的
让go程序在运行的时候就可以打印编译时候的参数情况

以gitlab-runner为例

最终实现的go程序运行时终端打印的信息如下

具体实现

入口文件
main.go

build编译构建脚本
build.sh

本质上是用 -ldflags 参数注入了的外部参数到go的变量当中
go的更多build参数帮助可以通过 go help build获取

问答

Q: 开发环境是windows,没有bash环境怎么办?
A: 都装了git的吧,那么用Git Bash终端是支持的

# Golang Build 官方发布 #

Sublime Text build system integration packages

Gophers,

This is our first stable release of a set of Sublime Text packages (v0.9.0):

  • ‘golangconfig’ is a developer library used to obtain information about the local Go environment. It handles configuration ($GOPATH, etc) through a combination of auto-detection and configuration. It is designed to be used by other Go-related Sublime Text packages.
  • ‘Golang Build’ provides Go toolchain integration with the Sublime build system – go build, go run, go install, go test. It is the first package to utilize the functionality of golangconfig.

Golang Build can be installed via packagecontrol.io:

  1. If you don’t already have Package Control installed, follow these instructions.
  2. Run the “Install Package” command via the command palette
  3. Type “Golang Build” and press enter

User documentation for Golang Build is available here. If you’d like to contribute to either package, there is also complete developer documentation available on Github (golangconfigGolang Build).


Please file bugs using the appropriate issue trackers on Github. For problems with Go environment detection and configuration, issues should be filed at:

For bugs related to the build command integration, issues should be filed at:

Our goal is to have other Go-related Sublime packages adopt golangconfig. This would allow users to set their Go environment configuration in one place and have that used by all of their installed Go/Sublime packages. If you are an author of a Go-related Sublime Text package, we’d love to hear your feedback on golangconfig.

Happy Editing,
The Go Team

Sublime Text 安装 GO说明

想必已经安装了st的插件管理器

直接安装名称为 “Golang Build “即可

Golang Build 源码  

Golang Build

Golang Build 文档

Golang Build 使用文档