Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/damdo/vcs
Go (1.18+) package to get the vcs info from the running binary
https://github.com/damdo/vcs
Last synced: about 9 hours ago
JSON representation
Go (1.18+) package to get the vcs info from the running binary
- Host: GitHub
- URL: https://github.com/damdo/vcs
- Owner: damdo
- License: mit
- Created: 2022-05-31T16:16:43.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-05-31T22:06:36.000Z (over 2 years ago)
- Last Synced: 2024-11-12T14:32:03.481Z (2 months ago)
- Language: Go
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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
```go
package mainimport (
"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:
```go
package mainimport (
"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)
}
}
}
```