refactor(config): centralize app name as pkg.NAME constant
Introduce pkg/name.go with a single exported NAME constant ("dragonscale")
and replace the package-private appName const in pkg/config/config.go with
a reference to pkg.NAME. This ensures the application name is defined in
exactly one place and can be consumed by any package without import cycles.
- pkg/name.go: new file, exports NAME = "dragonscale"
- pkg/config/config.go: remove local appName const; import pkg and use
pkg.NAME in ConfigDir, DataDir, CacheDir, DefaultDBPath
This commit is contained in:
parent
fdcd5fe385
commit
17f5143674
2 changed files with 8 additions and 6 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"runtime"
|
||||
"sync"
|
||||
|
||||
"github.com/ZanzyTHEbar/dragonscale/pkg"
|
||||
"github.com/caarlos0/env/v11"
|
||||
jsonv2 "github.com/go-json-experiment/json"
|
||||
"github.com/go-json-experiment/json/jsontext"
|
||||
|
|
@ -741,8 +742,6 @@ func expandHome(path string) string {
|
|||
|
||||
// ─── XDG / platform path helpers ─────────────────────────────────────────────
|
||||
|
||||
const appName = "dragonscale"
|
||||
|
||||
// ConfigDir returns the platform-appropriate user configuration directory for
|
||||
// dragonscale, following XDG Base Directory spec on Linux
|
||||
// (~/.config/dragonscale), Library/Application Support on macOS, and
|
||||
|
|
@ -752,7 +751,7 @@ func ConfigDir() (string, error) {
|
|||
if err != nil {
|
||||
return "", fmt.Errorf("resolve user config dir: %w", err)
|
||||
}
|
||||
dir := filepath.Join(base, appName)
|
||||
dir := filepath.Join(base, pkg.NAME)
|
||||
if err := os.MkdirAll(dir, 0o700); err != nil {
|
||||
return "", fmt.Errorf("create config dir %q: %w", dir, err)
|
||||
}
|
||||
|
|
@ -784,7 +783,7 @@ func DataDir() (string, error) {
|
|||
}
|
||||
base = cfgBase
|
||||
}
|
||||
dir := filepath.Join(base, appName)
|
||||
dir := filepath.Join(base, pkg.NAME)
|
||||
if err := os.MkdirAll(dir, 0o700); err != nil {
|
||||
return "", fmt.Errorf("create data dir %q: %w", dir, err)
|
||||
}
|
||||
|
|
@ -845,7 +844,7 @@ func CacheDir() (string, error) {
|
|||
if err != nil {
|
||||
return "", fmt.Errorf("resolve user cache dir: %w", err)
|
||||
}
|
||||
dir := filepath.Join(base, appName)
|
||||
dir := filepath.Join(base, pkg.NAME)
|
||||
if err := os.MkdirAll(dir, 0o700); err != nil {
|
||||
return "", fmt.Errorf("create cache dir %q: %w", dir, err)
|
||||
}
|
||||
|
|
@ -860,7 +859,7 @@ func DefaultDBPath() (string, error) {
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Join(dataDir, appName+".db"), nil
|
||||
return filepath.Join(dataDir, pkg.NAME+".db"), nil
|
||||
}
|
||||
|
||||
// DefaultConfigPath returns the path to the primary JSON config file inside
|
||||
|
|
|
|||
3
pkg/name.go
Normal file
3
pkg/name.go
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
package pkg
|
||||
|
||||
var NAME = "dragonscale"
|
||||
Loading…
Add table
Reference in a new issue