Read the architecture at run time, not via a Buildarch ldflag (closes #164)
check / check (push) Successful in 14s
check / check (push) Successful in 14s
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
This commit was merged in pull request #165.
This commit is contained in:
+12
-20
@@ -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
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user