-
Notifications
You must be signed in to change notification settings - Fork 153
/
version.go
46 lines (38 loc) · 971 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
// +build go1.12
package runtime
import (
"context"
"runtime/debug"
"github.com/influxdata/flux/values"
)
const modulePath = "github.com/influxdata/flux"
// readBuildInfo is used for reading the build information
// from the binary. This exists to overwrite the value for unit
// tests.
var readBuildInfo = debug.ReadBuildInfo
// Version returns the flux runtime version as a string.
func Version(ctx context.Context, args values.Object) (values.Value, error) {
bi, ok := readBuildInfo()
if !ok {
return nil, errBuildInfoNotPresent
}
// Find the module in the build info.
var m debug.Module
if bi.Main.Path == modulePath {
m = bi.Main
} else {
for _, dep := range bi.Deps {
if dep.Path == modulePath {
m = *dep
break
}
}
}
// Retrieve the version from the module.
v := m.Version
if m.Replace != nil {
// If the module has been replaced, take the version from it.
v = m.Replace.Version
}
return values.NewString(v), nil
}