Skip to content

Commit fe62512

Browse files
authored
Merge pull request #3 from grepplabs/feature/version
Add version command
2 parents a5cb828 + b003b08 commit fe62512

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

.goreleaser.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ builds:
1919
ldflags:
2020
# use commit date instead of current date as main.date
2121
# only needed if you actually use those things in your main package, otherwise can be ignored.
22-
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }}
22+
- -s -w -X github.com/grepplabs/reverse-http/config.Version={{.Version}} -X github.com/grepplabs/reverse-http/config.Commit={{.Commit}} -X github.com/grepplabs/reverse-http/config.Date={{ .CommitDate }}
2323

2424
# proxies from the go mod proxy before building
2525
# https://goreleaser.com/customization/gomod

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
66

77
BUILD_FLAGS ?=
8-
VERSION = "0.0.1"
8+
VERSION = "develop"
99
BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
1010
REVISION = $(shell git describe --tags --always --dirty)
1111
BUILD_DATE = $(shell date +'%Y.%m.%d-%H:%M:%S')
12-
LDFLAGS ?= -w -s
12+
LDFLAGS ?= -w -s \
13+
-X github.com/grepplabs/reverse-http/config.Version=${VERSION} \
14+
-X github.com/grepplabs/reverse-http/config.Commit=${REVISION} \
15+
-X github.com/grepplabs/reverse-http/config.Date=${BUILD_DATE}
16+
1317
BINARY = reverse-http
1418

1519
TEST_AGENT_ID = 4711

cmd/root.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"os"
67

@@ -20,6 +21,9 @@ type CLI struct {
2021
Proxy config.ProxyCmd `name:"proxy" cmd:"" help:"Start proxy server."`
2122
LoadBalancer config.LoadBalancerCmd `name:"lb" cmd:"" help:"Start load balancer."`
2223
Auth config.AuthCmd `name:"auth" cmd:"" help:"auth tools."`
24+
Version struct {
25+
Verbose bool `short:"V" help:"Verbose."`
26+
} `name:"version" cmd:"" help:"Show version"`
2327
}
2428

2529
func Execute() {
@@ -51,6 +55,16 @@ func Execute() {
5155
case "auth jwt token":
5256
err := runAuthJwtToken(&cli.Auth.JwtCmd.TokenCmd)
5357
ctx.FatalIfErrorf(err)
58+
case "version":
59+
if cli.Version.Verbose {
60+
_ = json.NewEncoder(os.Stdout).Encode(map[string]any{
61+
"version": config.Version,
62+
"commit": config.Commit,
63+
"date": config.Date,
64+
})
65+
} else {
66+
fmt.Println(config.Version)
67+
}
5468
default:
5569
fmt.Println(ctx.Command())
5670
os.Exit(1)

config/version.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package config
2+
3+
var (
4+
Version = "dev"
5+
Commit = "none"
6+
Date = "unknown"
7+
)

0 commit comments

Comments
 (0)