Skip to content

Commit

Permalink
Merge pull request #29 from Snawoot/versioning
Browse files Browse the repository at this point in the history
embed version into binary
  • Loading branch information
Snawoot committed Mar 13, 2021
2 parents 4fe6636 + 4f72e31 commit ff3c0f6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
PROGNAME = hola-proxy
OUTSUFFIX = bin/$(PROGNAME)
VERSION := $(shell git describe)
BUILDOPTS = -a -tags netgo
LDFLAGS = -ldflags '-s -w -extldflags "-static"'
LDFLAGS = -ldflags '-s -w -extldflags "-static" -X main.version=$(VERSION)'

src = $(wildcard *.go)

Expand Down Expand Up @@ -59,9 +60,12 @@ fmt:
go fmt ./...

run:
go run .
go run $(LDFLAGS) .

.PHONY: clean all native fmt \
install:
go install $(BUILDOPTS) $(LDFLAGS) .

.PHONY: clean all native fmt install \
bin-native \
bin-linux-amd64 \
bin-linux-386 \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Pre-built binaries available on [releases](https://github.com/Snawoot/hola-proxy
Alternatively, you may install hola-proxy from source. Run within source directory

```
go install
make install
```

#### Docker
Expand Down
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

var (
PROTOCOL_WHITELIST map[string]bool
version = "undefined"
)

func init() {
Expand Down Expand Up @@ -44,6 +45,7 @@ type CLIArgs struct {
proxy_type string
resolver string
force_port_field string
showVersion bool
}

func parse_args() CLIArgs {
Expand All @@ -64,6 +66,7 @@ func parse_args() CLIArgs {
"DNS/DoH/DoT resolver to workaround Hola blocked hosts. "+
"See https://github.com/ameshkov/dnslookup/ for upstream DNS URL format.")
flag.BoolVar(&args.use_trial, "dont-use-trial", false, "use regular ports instead of trial ports") // would be nice to not show in help page
flag.BoolVar(&args.showVersion, "version", false, "show program version and exit")
flag.Parse()
if args.country == "" {
arg_fail("Country can't be empty string.")
Expand All @@ -79,6 +82,11 @@ func parse_args() CLIArgs {

func run() int {
args := parse_args()
if args.showVersion {
fmt.Println(version)
return 0
}

if args.list_countries {
return print_countries(args.timeout)
}
Expand All @@ -98,6 +106,7 @@ func run() int {
proxyLogger := NewCondLogger(log.New(logWriter, "PROXY : ",
log.LstdFlags|log.Lshortfile),
args.verbosity)
mainLogger.Info("hola-proxy client version %s is starting...", version)
mainLogger.Info("Constructing fallback DNS upstream...")
resolver, err := NewResolver(args.resolver, args.timeout)
if err != nil {
Expand All @@ -120,6 +129,7 @@ func run() int {
mainLogger.Info("Endpoint: %s", endpoint)
mainLogger.Info("Starting proxy server...")
handler := NewProxyHandler(endpoint, auth, resolver, proxyLogger)
mainLogger.Info("Init complete.")
err = http.ListenAndServe(args.bind_address, handler)
mainLogger.Critical("Server terminated with a reason: %v", err)
mainLogger.Info("Shutting down...")
Expand Down

0 comments on commit ff3c0f6

Please sign in to comment.