The Echo Server version is dynamically injected at build time using Go's -ldflags feature. This avoids hardcoding the version in the source code.
The version is stored in a variable in main.go:
// Version is set via ldflags at build time
var Version = "dev"At build time, the value is replaced using:
go build -ldflags "-X main.Version=YOUR_VERSION"The Makefile automatically extracts the version from git:
# Build with version from git
make build
# Run with version from git
make run
# See what version would be used
make versionVersion resolution priority:
- Latest git tag + commit (e.g.,
v1.2.3-5-gabcdef) - Current commit hash (if no tags exist)
- "dev" (if not in a git repository)
Specify any version manually:
# With specific version
go build -ldflags "-X main.Version=1.0.0" -o echo-server
# With git tag
VERSION=$(git describe --tags --always --dirty)
go build -ldflags "-X main.Version=$VERSION" -o echo-server
# Development build (uses default "dev")
go build -o echo-serverThe Dockerfile automatically injects the git version:
docker build -t echo-server:latest .To create a versioned release:
# Create and push a tag
git tag -a v1.0.0 -m "Release version 1.0.0"
git push origin v1.0.0
# Build with the new version
make build
./echo-serverThe version appears in:
- Application startup logs
- Fiber app name:
Echo Server {VERSION} - HTML template footer
- Response metadata (via
Versionfield)
For automated builds, inject the version from your CI system:
# GitHub Actions
go build -ldflags "-X main.Version=${{ github.ref_name }}"
# GitLab CI
go build -ldflags "-X main.Version=$CI_COMMIT_TAG"
# Generic CI with version file
VERSION=$(cat VERSION)
go build -ldflags "-X main.Version=$VERSION"