-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
37 lines (31 loc) · 890 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
package common
import (
"runtime/debug"
"strings"
"github.com/blang/semver"
)
var (
// CompileTimeApplicationVersion is set at compile-time by application production builds
CompileTimeApplicationVersion string = ""
// LibraryVersion is determined at runtime based on the version of the lantern library that's been included.
LibraryVersion = ""
)
func init() {
buildInfo, ok := debug.ReadBuildInfo()
if !ok {
panic("Unable to read build info")
}
versionLoop:
for _, dep := range buildInfo.Deps {
if strings.HasPrefix(dep.Path, "github.com/getlantern/flashlight") && strings.HasPrefix(dep.Version, "v") {
version := dep.Version[1:]
log.Debugf("Flashlight version is %v", version)
_, parseErr := semver.Parse(version)
if parseErr == nil {
log.Debugf("Setting LibraryVersion to %v", version)
LibraryVersion = version
break versionLoop
}
}
}
}