From 402166561da5ba5726cdc275db174cb30e35e797 Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 1 Oct 2026 23:05:11 +0000 Subject: [PATCH] Read the architecture at run time, not via a Buildarch ldflag (closes #164) CONVENTIONS.md no longer passes the build architecture in through the Makefile. The Buildarch variable, globals field and BUILDARCH Makefile lines are removed from every example, and the logger's Identify example logs "arch", runtime.GOARCH, as internal/logger already does. Wording matches the HTTP server conventions in sneak/prompts. Model: opus-5-5 --- CONVENTIONS.md | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index 6a62434..9f8c1d3 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -112,15 +112,13 @@ import ( ) var ( - Appname string = "CHANGEME" - Version string - Buildarch string + Appname string = "CHANGEME" + Version string ) func main() { globals.Appname = Appname globals.Version = Version - globals.Buildarch = Buildarch fx.New( fx.Provide( @@ -859,7 +857,7 @@ 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, ) } ``` @@ -979,23 +977,20 @@ import "go.uber.org/fx" // Package-level variables (set from main) var ( - Appname string - Version string - Buildarch string + Appname string + Version string ) // Struct for DI type Globals struct { - Appname string - Version string - Buildarch string + Appname string + Version string } func New(lc fx.Lifecycle) (*Globals, error) { n := &Globals{ - Appname: Appname, - Buildarch: Buildarch, - Version: Version, + Appname: Appname, + Version: Version, } return n, nil } @@ -1006,15 +1001,13 @@ func New(lc fx.Lifecycle) (*Globals, error) { ```go // cmd/httpd/main.go var ( - Appname string = "CHANGEME" // Default, overridden by build - Version string // Set at build time - Buildarch string // Set at build time + Appname string = "CHANGEME" // Default, overridden by build + Version string // Set at build time ) func main() { globals.Appname = Appname globals.Version = Version - globals.Buildarch = Buildarch // ... } ``` @@ -1025,10 +1018,9 @@ Use ldflags to inject version information at build time: ```makefile VERSION := $(shell git describe --tags --always) -BUILDARCH := $(shell go env GOARCH) build: - go build -ldflags "-X main.Version=$(VERSION) -X main.Buildarch=$(BUILDARCH)" ./cmd/httpd + go build -ldflags "-X main.Version=$(VERSION)" ./cmd/httpd ``` ---