-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc.go
43 lines (34 loc) · 1.19 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) 2020, Roel Schut. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
/*
Package buildinfo provides basic building blocks and instructions to easily add
build and release information to your app.
# Using ldflags
Declare build info variables in your main package:
package main
// this value is changed via ldflags when building a new release
var version
func main() {
bld, err := buildinfo.New(version)
}
Build your Go project and include the following ldflags:
go build -ldflags=" \
-X main.version=`$(git describe --tags)` \
main.go
# Prometheus metric collector
When using a metrics scraper like Prometheus, it is often a good idea to make
the build information of your app available. Below example shows just how easy
it is to create and register a collector with the build information as
constant labels.
prometheus.MustRegister(prometheus.NewGaugeFunc(
prometheus.GaugeOpts{
Namespace: "myapp",
Name: buildinfo.MetricName,
Help: buildinfo.MetricHelp,
ConstLabels: bld.Map(),
},
func() float64 { return 1 },
))
*/
package buildinfo