consolidate appname to internal/globals as a constant
All checks were successful
check / check (push) Successful in 1m47s
All checks were successful
check / check (push) Successful in 1m47s
The appname was redundantly defined in both cmd/pixad/main.go and internal/globals/globals.go. Since it is always "pixad" and is not actually set via ldflags (only Version is), define it once as an unexported constant in globals.go and remove it from main.go.
This commit is contained in:
@@ -17,10 +17,7 @@ import (
|
|||||||
"sneak.berlin/go/pixa/internal/server"
|
"sneak.berlin/go/pixa/internal/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var Version string //nolint:gochecknoglobals // set by ldflags
|
||||||
Appname = "pixad" //nolint:gochecknoglobals // set by ldflags
|
|
||||||
Version string //nolint:gochecknoglobals // set by ldflags
|
|
||||||
)
|
|
||||||
|
|
||||||
var configPath string //nolint:gochecknoglobals // cobra flag
|
var configPath string //nolint:gochecknoglobals // cobra flag
|
||||||
|
|
||||||
@@ -40,7 +37,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run(_ *cobra.Command, _ []string) {
|
func run(_ *cobra.Command, _ []string) {
|
||||||
globals.Appname = Appname
|
|
||||||
globals.Version = Version
|
globals.Version = Version
|
||||||
|
|
||||||
// Set config path in environment if specified via flag
|
// Set config path in environment if specified via flag
|
||||||
|
|||||||
@@ -5,11 +5,10 @@ import (
|
|||||||
"go.uber.org/fx"
|
"go.uber.org/fx"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Build-time variables populated from main() via ldflags.
|
const appname = "pixad"
|
||||||
var (
|
|
||||||
Appname string //nolint:gochecknoglobals // set from main
|
// Version is populated from main() via ldflags.
|
||||||
Version string //nolint:gochecknoglobals // set from main
|
var Version string //nolint:gochecknoglobals // set from main
|
||||||
)
|
|
||||||
|
|
||||||
// Globals holds application-wide constants.
|
// Globals holds application-wide constants.
|
||||||
type Globals struct {
|
type Globals struct {
|
||||||
@@ -20,7 +19,7 @@ type Globals struct {
|
|||||||
// 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) {
|
||||||
return &Globals{
|
return &Globals{
|
||||||
Appname: Appname,
|
Appname: appname,
|
||||||
Version: Version,
|
Version: Version,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user