Skip to content

Commit b22cd29

Browse files
committed
Added version
1 parent fb4f9ec commit b22cd29

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

cmd/server/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type CLI struct {
3434
auth.UserCommands
3535
auth.TokenCommands
3636
auth.AuthCommands
37+
VersionCommands
3738
}
3839

3940
///////////////////////////////////////////////////////////////////////////////

cmd/server/version.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
7+
// Packages
8+
server "github.com/mutablelogic/go-server"
9+
version "github.com/mutablelogic/go-server/pkg/version"
10+
)
11+
12+
///////////////////////////////////////////////////////////////////////////////
13+
// TYPES
14+
15+
type VersionCommands struct {
16+
Version VersionCommand `cmd:"" group:"MISC" help:"Print version information"`
17+
}
18+
19+
type VersionCommand struct{}
20+
21+
///////////////////////////////////////////////////////////////////////////////
22+
// PUBLIC METHODS
23+
24+
func (cmd *VersionCommand) Run(app server.Cmd) error {
25+
// Print version information
26+
data, err := json.MarshalIndent(version.Map(), "", " ")
27+
if err != nil {
28+
return err
29+
}
30+
fmt.Println(string(data))
31+
return nil
32+
}

pkg/version/version.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package version
22

3+
import "runtime"
4+
35
///////////////////////////////////////////////////////////////////////////////
46
// GLOBALS
57

@@ -10,3 +12,25 @@ var (
1012
GitHash string
1113
GoBuildTime string
1214
)
15+
16+
////////////////////////////////////////////////////////////////////////////////
17+
// PRIVATE METHODS
18+
19+
func Map() map[string]any {
20+
vars := map[string]any{}
21+
if GitSource != "" {
22+
vars["source"] = GitSource
23+
}
24+
if GitTag != "" || GitBranch != "" {
25+
vars["version"] = GitTag
26+
vars["branch"] = GitBranch
27+
vars["hash"] = GitHash
28+
}
29+
if GoBuildTime != "" {
30+
vars["build"] = GoBuildTime
31+
}
32+
vars["go"] = runtime.Version()
33+
vars["os"] = runtime.GOOS
34+
vars["arch"] = runtime.GOARCH
35+
return vars
36+
}

0 commit comments

Comments
 (0)