detached 0bd81a6

feat(config): Set platform-appropriate default data directory in configuration

- Introduce getDefaultDataDir function to determine the default data directory based on the environment.
- Update Load function to set the default data_dir using the new method, enhancing compatibility for rootless environments.
commit
0bd81a6edbe9bcb6897f43306cb2c33fe0a12079
author
bamen · · 2025-06-07 08:53 UTC
parent
69d0d4b
signature
unsigned
1 file · +20 -1
M internal/config/config.go +20 -1
@@ -2,6 +2,8 @@ package config
22
33 import (
44 "fmt"
5+ "os"
6+ "path/filepath"
57 "strings"
68
79 "github.com/spf13/viper"
@@ -43,7 +45,10 @@ func Load() (*Config, error) {
4345 viper.SetDefault("server.registry_port", 5000)
4446 viper.SetDefault("server.runtime", "auto")
4547 viper.SetDefault("server.socket_path", "")
46- viper.SetDefault("server.data_dir", "./data")
48+
49+ // Set data_dir default based on environment
50+ defaultDataDir := getDefaultDataDir()
51+ viper.SetDefault("server.data_dir", defaultDataDir)
4752 viper.SetDefault("registry_auth.enabled", true)
4853
4954 // Handle the routes manually since Viper struggles with domain names
@@ -127,4 +132,18 @@ func (c *Config) GetRoutes() []Route {
127132 }
128133
129134 return routes
135+}
136+
137+// getDefaultDataDir returns a platform-appropriate default data directory
138+func getDefaultDataDir() string {
139+ // Check if we're running in a rootless environment
140+ if os.Getuid() != 0 {
141+ // For rootless environments, use user's home directory or current directory
142+ if homeDir, err := os.UserHomeDir(); err == nil {
143+ return filepath.Join(homeDir, ".local/share/gordon")
144+ }
145+ }
146+
147+ // For root or when home directory is not available, use relative path
148+ return "./data"
130149 }⏎̸
@@ -2,6 +2,8 @@ package config
2 2
3 import (3 import (
4 "fmt"4 "fmt"
5+ "os"
6+ "path/filepath"
5 "strings"7 "strings"
6 8
7 "github.com/spf13/viper"9 "github.com/spf13/viper"
@@ -43,7 +45,10 @@ func Load() (*Config, error) {
43 viper.SetDefault("server.registry_port", 5000)45 viper.SetDefault("server.registry_port", 5000)
44 viper.SetDefault("server.runtime", "auto")46 viper.SetDefault("server.runtime", "auto")
45 viper.SetDefault("server.socket_path", "")47 viper.SetDefault("server.socket_path", "")
46- viper.SetDefault("server.data_dir", "./data")48+
49+ // Set data_dir default based on environment
50+ defaultDataDir := getDefaultDataDir()
51+ viper.SetDefault("server.data_dir", defaultDataDir)
47 viper.SetDefault("registry_auth.enabled", true)52 viper.SetDefault("registry_auth.enabled", true)
48 53
49 // Handle the routes manually since Viper struggles with domain names54 // Handle the routes manually since Viper struggles with domain names
@@ -127,4 +132,18 @@ func (c *Config) GetRoutes() []Route {
127 }132 }
128 133
129 return routes134 return routes
135+}
136+
137+// getDefaultDataDir returns a platform-appropriate default data directory
138+func getDefaultDataDir() string {
139+ // Check if we're running in a rootless environment
140+ if os.Getuid() != 0 {
141+ // For rootless environments, use user's home directory or current directory
142+ if homeDir, err := os.UserHomeDir(); err == nil {
143+ return filepath.Join(homeDir, ".local/share/gordon")
144+ }
145+ }
146+
147+ // For root or when home directory is not available, use relative path
148+ return "./data"
130 }⏎̸149 }⏎̸

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close