-
Notifications
You must be signed in to change notification settings - Fork 225
/
buildinfo.go
69 lines (59 loc) · 1.12 KB
/
buildinfo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package buildinfo
import (
"fmt"
"os"
"path/filepath"
"runtime"
"time"
"github.com/blang/semver"
)
var cachedName string // populated during init
func init() {
var err error
if cachedName, err = os.Executable(); err != nil {
panic(err)
}
cachedName = filepath.Base(cachedName)
}
// Name returns the name for the executable that started the current
// process.
//
// Name is safe for concurrent use.
func Name() string {
return cachedName
}
type info struct {
Name string
Version semver.Version
Commit string
BuildDate time.Time
OS string
Architecture string
Environment string
}
func (i info) String() string {
return fmt.Sprintf("%s v%s %s/%s Commit: %s BuildDate: %s",
i.Name,
i.Version,
i.OS,
i.Architecture,
i.Commit,
i.BuildDate.Format(time.RFC3339))
}
func Info() info {
return info{
Name: Name(),
Version: Version(),
Commit: Commit(),
BuildDate: BuildDate(),
OS: OS(),
Architecture: Arch(),
Environment: Environment(),
}
}
func OS() string {
return runtime.GOOS
}
func Arch() string {
return runtime.GOARCH
}