build

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: MIT Imports: 8 Imported by: 0

README

Build

License Go Reference Go Report Card GitHub CI codecov

Project Description

Ridiculously simple Go build info 🛠️

Installation

go get github.com/FollowTheProcess/build@latest

Quickstart

package main

import (
	"fmt"
	"os"

	"github.com/FollowTheProcess/build"
)

func main() {
	info, ok := build.Info()
	if !ok {
		fmt.Fprintf(os.Stderr, "could not get build info")
		os.Exit(1)
	}

	fmt.Printf("%s\n", info)
}

Gets you...

go:           go1.23.2
path:         github.com/FollowTheProcess/build/cmd/build
os:           darwin
arch:         amd64
vcs:          git
version:      (devel)
commit:       5e8b8a68867eff5f754bfecdbc8baeb2c14c711c
dirty:        true
time:         2024-10-06T10:39:12Z
main:         mod  github.com/FollowTheProcess/build  (devel)  
-buildmode:   exe
-compiler:    gc
-ldflags:     -X main.version=dev
CGO_ENABLED:  0
GOAMD64:      v1

[!TIP] It's also JSON serialisable!

package main

import (
	"encoding/json"
	"fmt"
	"os"

	"github.com/FollowTheProcess/build"
)

func main() {
	info, _ := build.Info()
	if err := json.NewEncoder(os.Stdout).Encode(info); err != nil {
		fmt.Fprintf(os.Stderr, "could not write JSON: %v\n", err)
		os.Exit(1)
	}
}

Gets you...

{
  "main": {
    "path": "github.com/FollowTheProcess/build",
    "version": "(devel)"
  },
  "time": "2024-10-06T10:39:12Z",
  "settings": {
    "-buildmode": "exe",
    "-compiler": "gc",
    "-ldflags": "-X main.version=dev",
    "CGO_ENABLED": "0",
    "GOAMD64": "v1"
  },
  "go": "go1.23.2",
  "path": "github.com/FollowTheProcess/build/cmd/build",
  "os": "darwin",
  "arch": "amd64",
  "vcs": "git",
  "version": "(devel)",
  "dirty": true
}
Credits

This package is wholly based on the Go internal implementation of runtime/debug.BuildInfo, this is just a slightly nicer wrapper that makes it easier to access common settings

Documentation

Overview

Package build provides a simple mechanism for getting at debug.BuildInfo in a more ergonomic way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildInfo

type BuildInfo struct {
	Main     Module            `json:"main,omitempty"`     // The main module
	Time     time.Time         `json:"time,omitempty"`     // The modification time associated with Commit
	Settings map[string]string `json:"settings,omitempty"` // The remaining settings
	Go       string            `json:"go,omitempty"`       // The Go toolchain version used to build the binary
	Path     string            `json:"path,omitempty"`     // The package path of the main package
	OS       string            `json:"os,omitempty"`       // The value of $GOOS
	Arch     string            `json:"arch,omitempty"`     // The value of $GOARCH
	VCS      string            `json:"vcs,omitempty"`      // The version control system for the source tree where the build ran
	Commit   string            `json:"commit,omitempty"`   // The SHA1 of the current commit when the build ran
	Version  string            `json:"version,omitempty"`  // The module version
	Dirty    bool              `json:"dirty,omitempty"`    // Whether the source tree had local modifications at the time of the build
}

BuildInfo contains the build information of a Go binary.

func Info

func Info() (info BuildInfo, ok bool)

Info returns the Go build info for the current binary.

func (BuildInfo) String

func (b BuildInfo) String() string

String implements fmt.Stringer for BuildInfo.

type Module

type Module struct {
	Path    string `json:"path,omitempty"`    // module path
	Version string `json:"version,omitempty"` // module version
	Sum     string `json:"sum,omitempty"`     // checksum
}

A Module describes a single module included in a build.

Jump to

Keyboard shortcuts

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