fix: remove Buildarch from globals, main, Makefile, logger, and tests
All checks were successful
check / check (push) Successful in 4s
All checks were successful
check / check (push) Successful in 4s
Buildarch was erroneously included. Remove it from: - internal/globals/globals.go (struct field, package var, setter) - cmd/dnswatcher/main.go (var declaration, setter call) - Makefile (BUILDARCH var, ldflags) - internal/logger/logger.go (Identify log field) - internal/config/config_test.go (test fixture) - README.md (build command, architecture section)
This commit is contained in:
3
Makefile
3
Makefile
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
BINARY := dnswatcher
|
BINARY := dnswatcher
|
||||||
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
||||||
BUILDARCH := $(shell go env GOARCH)
|
LDFLAGS := -X main.Version=$(VERSION)
|
||||||
LDFLAGS := -X main.Version=$(VERSION) -X main.Buildarch=$(BUILDARCH)
|
|
||||||
|
|
||||||
all: check build
|
all: check build
|
||||||
|
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ cmd/dnswatcher/main.go Entry point (uber/fx bootstrap)
|
|||||||
|
|
||||||
internal/
|
internal/
|
||||||
config/config.go Viper-based configuration
|
config/config.go Viper-based configuration
|
||||||
globals/globals.go Build-time variables (version, arch)
|
globals/globals.go Build-time variables (version)
|
||||||
logger/logger.go slog structured logging (TTY detection)
|
logger/logger.go slog structured logging (TTY detection)
|
||||||
healthcheck/healthcheck.go Health check service
|
healthcheck/healthcheck.go Health check service
|
||||||
middleware/middleware.go HTTP middleware (logging, CORS, metrics auth)
|
middleware/middleware.go HTTP middleware (logging, CORS, metrics auth)
|
||||||
@@ -363,11 +363,10 @@ make clean # Remove build artifacts
|
|||||||
|
|
||||||
### Build-Time Variables
|
### Build-Time Variables
|
||||||
|
|
||||||
Version and architecture are injected via `-ldflags`:
|
Version is injected via `-ldflags`:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
go build -ldflags "-X main.Version=$(git describe --tags --always) \
|
go build -ldflags "-X main.Version=$(git describe --tags --always)" ./cmd/dnswatcher
|
||||||
-X main.Buildarch=$(go env GOARCH)" ./cmd/dnswatcher
|
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -25,15 +25,13 @@ import (
|
|||||||
//
|
//
|
||||||
//nolint:gochecknoglobals // build-time variables
|
//nolint:gochecknoglobals // build-time variables
|
||||||
var (
|
var (
|
||||||
Appname = "dnswatcher"
|
Appname = "dnswatcher"
|
||||||
Version string
|
Version string
|
||||||
Buildarch string
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
globals.SetAppname(Appname)
|
globals.SetAppname(Appname)
|
||||||
globals.SetVersion(Version)
|
globals.SetVersion(Version)
|
||||||
globals.SetBuildarch(Buildarch)
|
|
||||||
|
|
||||||
fx.New(
|
fx.New(
|
||||||
fx.Provide(
|
fx.Provide(
|
||||||
|
|||||||
@@ -19,9 +19,8 @@ func newTestParams(t *testing.T) config.Params {
|
|||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
g := &globals.Globals{
|
g := &globals.Globals{
|
||||||
Appname: "dnswatcher",
|
Appname: "dnswatcher",
|
||||||
Version: "test",
|
Version: "test",
|
||||||
Buildarch: "amd64",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
l, err := logger.New(nil, logger.Params{Globals: g})
|
l, err := logger.New(nil, logger.Params{Globals: g})
|
||||||
|
|||||||
@@ -12,17 +12,15 @@ import (
|
|||||||
//
|
//
|
||||||
//nolint:gochecknoglobals // Required for ldflags injection at build time
|
//nolint:gochecknoglobals // Required for ldflags injection at build time
|
||||||
var (
|
var (
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
appname string
|
appname string
|
||||||
version string
|
version string
|
||||||
buildarch string
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Globals holds build-time variables for dependency injection.
|
// Globals holds build-time variables for dependency injection.
|
||||||
type Globals struct {
|
type Globals struct {
|
||||||
Appname string
|
Appname string
|
||||||
Version string
|
Version string
|
||||||
Buildarch string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new Globals instance from package-level variables.
|
// New creates a new Globals instance from package-level variables.
|
||||||
@@ -31,9 +29,8 @@ func New(_ fx.Lifecycle) (*Globals, error) {
|
|||||||
defer mu.RUnlock()
|
defer mu.RUnlock()
|
||||||
|
|
||||||
return &Globals{
|
return &Globals{
|
||||||
Appname: appname,
|
Appname: appname,
|
||||||
Version: version,
|
Version: version,
|
||||||
Buildarch: buildarch,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,11 +49,3 @@ func SetVersion(ver string) {
|
|||||||
|
|
||||||
version = ver
|
version = ver
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetBuildarch sets the build architecture.
|
|
||||||
func SetBuildarch(arch string) {
|
|
||||||
mu.Lock()
|
|
||||||
defer mu.Unlock()
|
|
||||||
|
|
||||||
buildarch = arch
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -78,6 +78,5 @@ func (l *Logger) Identify() {
|
|||||||
l.log.Info("starting",
|
l.log.Info("starting",
|
||||||
"appname", l.params.Globals.Appname,
|
"appname", l.params.Globals.Appname,
|
||||||
"version", l.params.Globals.Version,
|
"version", l.params.Globals.Version,
|
||||||
"buildarch", l.params.Globals.Buildarch,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user