diff --git a/Makefile b/Makefile index f43fbb38f98fb6d1edd87e9f9d78f5b7bb726222..8f34902804d2bb8bf1aaf145c4e2e20016cc684d 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,7 @@ $(BIN_DIR)/artifact.bin: cd $(SRC_DIR) \ && go build \ -o $(@) \ + -ldflags "-X webservice/configuration.version=0.0.1" \ $(SRC_DIR)/*.go .PHONY: build-linux diff --git a/README.md b/README.md index e8c68c9719b9c5074af010df1d4a5c9a758fe6b2..74b1ca89162950f7a271a25424d3711f58bf123c 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,11 @@ information checkout the [configuration code](./configuration/config.go). 3. Execute unit tests: `go test -race -v ./...` 4. Build artifact: `go build -o ./artifact.bin ./*.go` -To build for another platform, set `GOOS` and `GOARCH`. To yield a static binary (fully -self-contained, no dynamic linking) set `CGO_ENABLED=0`. For more details, please refer -to the [Makefile](./Makefile). +To build for another platform, set `GOOS` and `GOARCH`. To yield a static +binary (fully self-contained, no dynamic linking) set `CGO_ENABLED=0`. +To set a version during build time, add the following CLI option +`-ldflags "-X webservice/configuration.version=${VERSION}"`. +For more information, please refer to the [Makefile](./Makefile). #### Run: diff --git a/configuration/config.go b/configuration/config.go index be25fb69e12875962685a8388fb6ebdd2b97d3ab..2286c4bfaecc66ab4be8451cde9f91bb8a224fc8 100644 --- a/configuration/config.go +++ b/configuration/config.go @@ -12,9 +12,11 @@ import ( const BODY_SIZE_LIMIT = 32 * 1024 * 1024 // 32 MB, in bytes +var version string = "n/a" + type Config struct { - Version string `env:"VERSION" envDefault:"N/A"` + Version string LogLevel string `env:"LOG_LEVE" envDefault:"error"` @@ -31,7 +33,9 @@ type Config struct { func New() ( *Config, error ){ - cfg := Config{} + cfg := Config{ + Version: version, + } if err := configParser.Parse( &cfg ); err != nil { return nil, err