inspect

package
v0.0.0-...-110d06e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Info

func Info() *inspector

Info 编译信息,即通过连接器参数将编译信息写入程序,参考 docker version 命令

调用示例: fmt.Println(inspect.Info())
# Output:
Build Info:
 App Name:     awesome
 Version:      v1.0.0
 OS/Arch:      amd64
 Go version:   go1.17.8
 GOOS:         darwin
 Git Branch:   origin/dev
 Git Commit:   fedc48b
 Git Author:   hollson
 Git Tag:      list
 Machine:      shs
 Environment:  develop
 Built:        2022-12-01 15:04:05

运行示例(编译时传入连接器参数):
$ go run -ldflags \
"-X 'github.com/hollson/gdk/inspect.name=awesome'
 -X 'github.com/hollson/gdk/inspect.version=v1.0.0'
 -X 'github.com/hollson/gdk/inspect.branch=$(git rev-parse --abbrev-ref @{u})'
 -X 'github.com/hollson/gdk/inspect.commit=$(git rev-parse --short HEAD)'
 -X 'github.com/hollson/gdk/inspect.author=$(git config user.name)'
 -X 'github.com/hollson/gdk/inspect.tag=$(git describe --tags --abbrev=0)'
 -X 'github.com/hollson/gdk/inspect.machine=$(hostname)'
 -X 'github.com/hollson/gdk/inspect.environment=develop'
 -X 'github.com/hollson/gdk/inspect.built=$(date "+%Y-%m-%d %H:%M:%S")'" \
 main.go

另一个推荐方案,是将编译信息写入version文件。

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL