https://github.com/followtheprocess/build
Ridiculously easy debug.BuildInfo
https://github.com/followtheprocess/build
Last synced: 2 months ago
JSON representation
Ridiculously easy debug.BuildInfo
- Host: GitHub
- URL: https://github.com/followtheprocess/build
- Owner: FollowTheProcess
- License: mit
- Created: 2024-10-06T15:17:51.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-18T09:04:13.000Z (9 months ago)
- Last Synced: 2025-03-18T10:23:05.710Z (9 months ago)
- Language: Go
- Size: 134 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Build
[](https://github.com/FollowTheProcess/build)
[](https://pkg.go.dev/go.followtheprocess.codes/build)
[](https://goreportcard.com/report/github.com/FollowTheProcess/build)
[](https://github.com/FollowTheProcess/build)
[](https://github.com/FollowTheProcess/build/actions?query=workflow%3ACI)
[](https://codecov.io/gh/FollowTheProcess/build)
## Project Description
Ridiculously simple Go build info 🛠️
## Installation
```shell
go get go.followtheprocess.codes/build@latest
```
## Quickstart
```go
package main
import (
"fmt"
"os"
"go.followtheprocess.codes/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...
```shell
go: go1.23.2
path: go.followtheprocess.codes/build/cmd/build
os: darwin
arch: amd64
vcs: git
version: (devel)
commit: 5e8b8a68867eff5f754bfecdbc8baeb2c14c711c
dirty: true
time: 2024-10-06T10:39:12Z
main: mod go.followtheprocess.codes/build (devel)
```
> [!TIP]
> It's also JSON serialisable!
```go
package main
import (
"encoding/json"
"fmt"
"os"
"go.followtheprocess.codes/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...
```json
{
"main": {
"path": "go.followtheprocess.codes/build",
"version": "(devel)"
},
"time": "2024-10-06T10:39:12Z",
"go": "go1.23.2",
"path": "go.followtheprocess.codes/build/cmd/build",
"os": "darwin",
"arch": "amd64",
"vcs": "git",
"version": "(devel)",
"dirty": true
}
```
`build.Info` returns a `BuildInfo` struct from which you can take any component of the build info:
```go
package main
import (
"fmt"
"os"
"go.followtheprocess.codes/build"
)
func main() {
info, ok := build.Info()
if !ok {
fmt.Fprintf(os.Stderr, "could not get build info")
os.Exit(1)
}
fmt.Printf("Version: %s\n", info.Version)
fmt.Printf("Commit: %s\n", info.Commit)
}
```
### 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