tangled
alpha
login
or
join now
julien.rbrt.fr
/
servmon
0
fork
atom
kiss server monitoring tool with email alerts
go
monitoring
0
fork
atom
overview
issues
pulls
pipelines
refactor: add dynamic version
julien.rbrt.fr
1 year ago
33aa4f22
6c316252
+18
-1
1 changed file
expand all
collapse all
unified
split
main.go
+18
-1
main.go
···
1
1
package main
2
2
3
3
import (
4
4
+
"errors"
4
5
"fmt"
5
6
"os"
6
7
"os/exec"
7
8
"path"
8
9
"runtime"
10
10
+
"runtime/debug"
11
11
+
"strings"
9
12
10
13
"github.com/spf13/cobra"
11
14
)
12
15
13
16
var (
14
14
-
version = "1.0.0"
15
17
flagConfig = "config"
16
18
flagDaemon = "daemon"
17
19
cfgFile string
···
23
25
if err != nil {
24
26
fmt.Fprintf(os.Stderr, "error getting user home directory: %v", err)
25
27
os.Exit(1)
28
28
+
}
29
29
+
30
30
+
version, err := getVersion()
31
31
+
if err != nil {
32
32
+
fmt.Fprintf(os.Stderr, "error getting version: %v", err)
33
33
+
version = "unknown"
26
34
}
27
35
28
36
rootCmd := &cobra.Command{
···
117
125
118
126
return 0, fmt.Errorf("daemon mode is not supported on %s", runtime.GOOS)
119
127
}
128
128
+
129
129
+
func getVersion() (string, error) {
130
130
+
version, ok := debug.ReadBuildInfo()
131
131
+
if !ok {
132
132
+
return "", errors.New("failed to get version")
133
133
+
}
134
134
+
135
135
+
return strings.TrimSpace(version.Main.Version), nil
136
136
+
}