Latest release
Build status
Go Report Card

Package buildinfo provides basic building blocks and instructions to easily add
build and release information to your app. This is done by replacing variables
in main during build with ldflags.

go get

import ""


Declare build info variables in your main package:

package main

// these values are changed via ldflags when building a new release
var (
    version = buildinfo.DummyVersion
    revision = buildinfo.DummyRevision
    date = buildinfo.DummyDate

func main() {
    bld := buildinfo.BuildInfo{
        Version:  version,
        Revision: revision,
        Date:     date,

Build your Go project and include the following ldflags:

go build -ldflags=" \
  -X main.version=`$(git describe --tags)` \
  -X main.revision=`$(git rev-parse --short HEAD)` \
  -X`$(date +%FT%T%z`)" \

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.

        Namespace:   "myapp",
        Name:        buildinfo.MetricName,
        Help:        buildinfo.MetricHelp,
        ConstLabels: bld.Map(),
    func() float64 { return 1 },


Additional detailed documentation is available at

Created with


Copyright © 2020 Roel Schut. All rights reserved.

This project is governed by a BSD-style license that can be found in the LICENSE file.


View Github