Read the architecture at run time instead of a Buildarch ldflag (closes #259)
Check / check (pull_request) Successful in 5m19s
Check / check (pull_request) Successful in 5m19s
The Makefile no longer passes the architecture to the linker. The Buildarch variable in main and the field and setter in globals are gone; the startup log line reports runtime.GOARCH as `arch`. CONVENTIONS.md drops Buildarch from its main, globals, logger and Makefile examples, as the sneak/prompts conventions do. Model: opus-5-5
This commit was merged in pull request #265.
This commit is contained in:
@@ -12,17 +12,15 @@ import (
|
||||
//
|
||||
//nolint:gochecknoglobals // Required for ldflags injection at build time
|
||||
var (
|
||||
mu sync.RWMutex
|
||||
appname string
|
||||
version string
|
||||
buildarch string
|
||||
mu sync.RWMutex
|
||||
appname string
|
||||
version string
|
||||
)
|
||||
|
||||
// Globals holds build-time variables for dependency injection.
|
||||
type Globals struct {
|
||||
Appname string
|
||||
Version string
|
||||
Buildarch string
|
||||
Appname string
|
||||
Version string
|
||||
}
|
||||
|
||||
// New creates a new Globals instance from package-level variables.
|
||||
@@ -31,9 +29,8 @@ func New(_ fx.Lifecycle) (*Globals, error) {
|
||||
defer mu.RUnlock()
|
||||
|
||||
return &Globals{
|
||||
Appname: appname,
|
||||
Version: version,
|
||||
Buildarch: buildarch,
|
||||
Appname: appname,
|
||||
Version: version,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -52,11 +49,3 @@ func SetVersion(ver string) {
|
||||
|
||||
version = ver
|
||||
}
|
||||
|
||||
// SetBuildarch sets the build architecture (used for testing and main init).
|
||||
func SetBuildarch(arch string) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
buildarch = arch
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package logger
|
||||
import (
|
||||
"log/slog"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"go.uber.org/fx"
|
||||
|
||||
@@ -81,6 +82,6 @@ func (l *Logger) Identify() {
|
||||
l.log.Info("starting",
|
||||
"appname", l.params.Globals.Appname,
|
||||
"version", l.params.Globals.Version,
|
||||
"buildarch", l.params.Globals.Buildarch,
|
||||
"arch", runtime.GOARCH,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package logger //nolint:testpackage // sets the unexported log and params fields
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"sneak.berlin/go/upaas/internal/globals"
|
||||
)
|
||||
|
||||
func TestIdentifyLogsArchitectureFromRuntime(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var buf bytes.Buffer
|
||||
|
||||
l := &Logger{
|
||||
log: slog.New(slog.NewJSONHandler(&buf, nil)),
|
||||
params: Params{
|
||||
Globals: &globals.Globals{Appname: "upaas-test", Version: "test"},
|
||||
},
|
||||
}
|
||||
|
||||
l.Identify()
|
||||
|
||||
var line map[string]any
|
||||
|
||||
require.NoError(t, json.Unmarshal(buf.Bytes(), &line))
|
||||
assert.Equal(t, runtime.GOARCH, line["arch"])
|
||||
}
|
||||
Reference in New Issue
Block a user