Skip to content

Commit

Permalink
Show version information based on build metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
securitym0nkey committed May 25, 2024
1 parent 0f70450 commit 5446fc7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/icalm-benchmark/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"sync"
"time"
"github.com/securitym0nkey/icalm/internal/config"
)

var version string = "v0.0.0-dev"
Expand Down Expand Up @@ -56,6 +57,7 @@ func stress(network string, addr string, stop int) (time.Duration, int, int) {
}

func main() {
version = config.VersionString()
var pFlag = flag.Int("p", runtime.NumCPU()/2, "Count of parallel worker routines to send queries")
var cFlag = flag.Int("c", 100000, "Amount of quries to do with each worker routine")
var versionFlag = flag.Bool("version", false, "Prints version and exists")
Expand Down
1 change: 1 addition & 0 deletions cmd/icalm-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var version string = "v0.0.0-dev"


func main() {
version = config.VersionString()

var httplistenFlag = flag.String("http-listen", "", "Address on which the server will listen for http requests. Example: 127.0.0.1:8226")
var linelistenFlag = flag.String("line-listen", "", "Address on which the server will listen for line-protocol requests. Example: 127.0.0.1:4226")
Expand Down
33 changes: 33 additions & 0 deletions internal/config/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package config

import (
"runtime/debug"
"strings"
)

func VersionString() string {
version := "v0.0.0-unknown"
if info, ok := debug.ReadBuildInfo(); ok {
for _, s := range info.Settings {
switch s.Key {
case "-tags":
for _, t := range strings.Split(s.Value, ",") {
if len(t) > 0 && t[0] == 'v' {
return t
}
}
case "vcs":
version = s.Value
case "vcs.revision":
if version == "git" && len(s.Value) >= 10 {
version += "-" + s.Value[:10]
}
case "vcs.modified":
if s.Value == "true" {
return (version + "-modified")
}
}
}
}
return version
}

0 comments on commit 5446fc7

Please sign in to comment.