vcs

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2022 License: MIT Imports: 2 Imported by: 0

README

vcs

Read the vcs information (BuildInfo data) embedded in the running go binary.

requirements

Note: Go BuildInfo's VCS data to be available in the running binary the following requirements must be satisfied:

  • Binary must be built with Go 1.18 or greater
  • When the binary is built, the build context folder must already be initialized by the vcs system (e.g. for git, git init)
  • The go build ... invocation must include the whole directory and not just specific go files (e.g. go build .)
usage
package main

import (
	"github.com/damdo/vcs"
	"fmt"
)

func main() {
	v, ok := vcs.ReadInfo()
	if ok {
		fmt.Println(v.Vcs, v.Revision, v.Time, v.Modified)
	}
}

or if you prefer to gather BuildInfo on your own:

package main

import (
	"github.com/damdo/vcs"
	"fmt"
	"runtime/debug"
)

func main() {
	b, ok := debug.ReadBuildInfo()
	if ok {
		v, ok := vcs.FromBuildInfo(b)
		if ok {
			fmt.Println(v.Vcs, v.Revision, v.Time, v.Modified)
		}
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Vcs

type Vcs struct {
	Vcs      string
	Revision string
	Time     string
	Modified bool
}

func FromBuildInfo

func FromBuildInfo(info *debug.BuildInfo) (*Vcs, bool)

FromBuildInfo returns the vcs information embedded in the provided BuildInfo object. The information is available only in binaries built with module support. And for go 1.18+.

func ReadInfo

func ReadInfo() (*Vcs, bool)

ReadInfo returns the vcs information embedded in the running binary. The information is available only in binaries built with module support. And for go 1.18+.

Jump to

Keyboard shortcuts

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