Skip to content
Snippets Groups Projects
Commit 09fd2dfb authored by gjahn's avatar gjahn
Browse files

Allow to set version during build time

parent 120ca78d
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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:
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment