Remove Buildarch from ldflags, use runtime.GOARCH instead

The architecture is available at runtime via stdlib, no need to bake
it in at build time.
This commit is contained in:
2026-01-08 12:38:24 -08:00
parent 15d9439e3d
commit 7d0ac0a139
4 changed files with 13 additions and 20 deletions

View File

@@ -1,8 +1,7 @@
.PHONY: check lint test fmt build clean .PHONY: check lint test fmt build clean
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)
# Default target: run all checks # Default target: run all checks
check: fmt-check lint test check: fmt-check lint test

View File

@@ -20,7 +20,6 @@ import (
var ( var (
Appname = "pixad" //nolint:gochecknoglobals // set by ldflags Appname = "pixad" //nolint:gochecknoglobals // set by ldflags
Version string //nolint:gochecknoglobals // set by ldflags Version string //nolint:gochecknoglobals // set by ldflags
Buildarch string //nolint:gochecknoglobals // set by ldflags
) )
var configPath string //nolint:gochecknoglobals // cobra flag var configPath string //nolint:gochecknoglobals // cobra flag
@@ -43,7 +42,6 @@ func main() {
func run(_ *cobra.Command, _ []string) { func run(_ *cobra.Command, _ []string) {
globals.Appname = Appname globals.Appname = Appname
globals.Version = Version globals.Version = Version
globals.Buildarch = Buildarch
// Set config path in environment if specified via flag // Set config path in environment if specified via flag
if configPath != "" { if configPath != "" {

View File

@@ -9,23 +9,18 @@ import (
var ( var (
Appname string //nolint:gochecknoglobals // set from main Appname string //nolint:gochecknoglobals // set from main
Version string //nolint:gochecknoglobals // set from main Version string //nolint:gochecknoglobals // set from main
Buildarch string //nolint:gochecknoglobals // set from main
) )
// Globals holds application-wide constants. // Globals holds application-wide constants.
type Globals struct { type Globals struct {
Appname string Appname string
Version string Version string
Buildarch string
} }
// New creates a new Globals instance from build-time variables. // New creates a new Globals instance from build-time variables.
func New(_ fx.Lifecycle) (*Globals, error) { func New(_ fx.Lifecycle) (*Globals, error) {
n := &Globals{ return &Globals{
Appname: Appname, Appname: Appname,
Buildarch: Buildarch,
Version: Version, Version: Version,
} }, nil
return n, nil
} }

View File

@@ -4,6 +4,7 @@ package logger
import ( import (
"log/slog" "log/slog"
"os" "os"
"runtime"
"go.uber.org/fx" "go.uber.org/fx"
"sneak.berlin/go/pixa/internal/globals" "sneak.berlin/go/pixa/internal/globals"
@@ -72,6 +73,6 @@ func (l *Logger) Identify() {
l.log.Info("starting", l.log.Info("starting",
"appname", l.globals.Appname, "appname", l.globals.Appname,
"version", l.globals.Version, "version", l.globals.Version,
"buildarch", l.globals.Buildarch, "arch", runtime.GOARCH,
) )
} }