Add version command to print version info

This commit is contained in:
Anders Pitman
2022-01-07 14:36:16 -07:00
parent 6bfa3e9a47
commit bec4245764
4 changed files with 12 additions and 2 deletions

View File

@@ -49,6 +49,11 @@ cd cmd/boringproxy
go build
```
To build with version information:
```bash
go build -ldflags "-X main.Version=$(git describe --tags)"
```
Give the executable permission to bind low ports (ie 80/443):
```bash

View File

@@ -12,12 +12,15 @@ import (
const usage = `Usage: %s [command] [flags]
Commands:
version Prints version information.
server Start a new server.
client Connect to a server.
Use "%[1]s command -h" for a list of flags for the command.
`
var Version string
func fail(msg string) {
fmt.Fprintln(os.Stderr, msg)
os.Exit(1)
@@ -33,6 +36,8 @@ func main() {
command := os.Args[1]
switch command {
case "version":
fmt.Println(Version)
case "help", "-h", "--help", "-help":
fmt.Printf(usage, os.Args[0])
case "server":

View File

@@ -1,4 +1,4 @@
#!/bin/bash
echo Building platform $1-$2
CGO_ENABLED=0 GOOS=$1 GOARCH=$2 go build -o build/boringproxy-$1-$2$3
CGO_ENABLED=0 GOOS=$1 GOARCH=$2 go build -ldflags "-X main.Version=$(git describe --tags)" -o build/boringproxy-$1-$2$3

View File

@@ -1,4 +1,4 @@
#!/bin/bash
echo Building platform $1-x86_64
CGO_ENABLED=0 GOOS=$1 GOARCH=amd64 go build -o build/boringproxy-$1-x86_64$2
CGO_ENABLED=0 GOOS=$1 GOARCH=amd64 go build -ldflags "-X main.Version=$(git describe --tags)" -o build/boringproxy-$1-x86_64$2