-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathversion.go
47 lines (38 loc) · 796 Bytes
/
version.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
// Copyright (c) 2020, Compromised AUTHORS.
// All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package compromised
import "runtime/debug"
// automatically set on release
// and updated with vcs revision on init
var version = "0.0.0"
func init() {
info, ok := debug.ReadBuildInfo()
if !ok {
return
}
var revision string
var dirtyBuild bool
for _, s := range info.Settings {
switch s.Key {
case "vcs.revision":
revision = s.Value
case "vcs.modified":
dirtyBuild = s.Value == "true"
}
}
if len(revision) == 0 {
return
}
if len(revision) > 7 {
revision = revision[:7]
}
version += "-" + revision
if dirtyBuild {
version += "-dirty"
}
}
func Version() string {
return version
}