detached cc06cda

Refactor application configuration

- Rename StringsYML to LocYML in App struct for better clarity.
- Modify LoadConfig() to accept AppConfig as a parameter for more flexible configuration loading.
- Add debug output for configuration in NewApp().
- Update CreateContainerPOST to pass App instance to FromInputsToCmdParams.
- Change FromInputsToCmdParams to use the network configuration from App's Config.ContainerEngine.Network.
Update getLocalizations to use the new LocYML field for YAML unmarshalling.
commit
cc06cda7423193b25f8db61c89194ea0d4ce2bff
author
bnema · · 2023-10-09 13:51 UTC
parent
79543aa
signature
unsigned
4 files · +10 -9
M internal/app/app.go +5 -5
@@ -17,13 +17,12 @@ import (
1717
1818 var (
1919 OauthCallbackURL string
20- config AppConfig
2120 )
2221
2322 type App struct {
2423 TemplateFS fs.FS
2524 PublicFS fs.FS
26- StringsYML []byte // strings.yml contains the strings for the current language
25+ LocYML []byte // strings.yml contains the strings for the current language
2726 DBDir string
2827 DBFilename string
2928 DBPath string
@@ -62,7 +61,7 @@ type ContainerEngineConfig struct {
6261 Network string `yaml:"network"`
6362 }
6463
65-func LoadConfig() (AppConfig, error) {
64+func LoadConfig(config AppConfig) (AppConfig, error) {
6665 // Load env elements
6766 config.General.BuildVersion = os.Getenv("BUILD_VERSION")
6867 config.General.RunEnv = os.Getenv("RUN_ENV")
@@ -94,7 +93,8 @@ func LoadConfig() (AppConfig, error) {
9493
9594 func NewApp() *App {
9695 // Initialize AppConfig
97- config, err := LoadConfig()
96+ config, err := LoadConfig(AppConfig{})
97+ fmt.Printf("Config: %+v\n", config)
9898 if err != nil {
9999 log.Fatalf("Failed to load configuration: %v", err)
100100 }
@@ -117,7 +117,7 @@ func NewApp() *App {
117117 a := &App{
118118 TemplateFS: templates.TemplateFS,
119119 PublicFS: webui.PublicFS,
120- StringsYML: bytes,
120+ LocYML: bytes,
121121 DBDir: DBDir,
122122 DBFilename: DBFilename,
123123 Config: config,
@@ -17,13 +17,12 @@ import (
17 17
18 var (18 var (
19 OauthCallbackURL string19 OauthCallbackURL string
20- config AppConfig
21 )20 )
22 21
23 type App struct {22 type App struct {
24 TemplateFS fs.FS23 TemplateFS fs.FS
25 PublicFS fs.FS24 PublicFS fs.FS
26- StringsYML []byte // strings.yml contains the strings for the current language25+ LocYML []byte // strings.yml contains the strings for the current language
27 DBDir string26 DBDir string
28 DBFilename string27 DBFilename string
29 DBPath string28 DBPath string
@@ -62,7 +61,7 @@ type ContainerEngineConfig struct {
62 Network string `yaml:"network"`61 Network string `yaml:"network"`
63 }62 }
64 63
65-func LoadConfig() (AppConfig, error) {64+func LoadConfig(config AppConfig) (AppConfig, error) {
66 // Load env elements65 // Load env elements
67 config.General.BuildVersion = os.Getenv("BUILD_VERSION")66 config.General.BuildVersion = os.Getenv("BUILD_VERSION")
68 config.General.RunEnv = os.Getenv("RUN_ENV")67 config.General.RunEnv = os.Getenv("RUN_ENV")
@@ -94,7 +93,8 @@ func LoadConfig() (AppConfig, error) {
94 93
95 func NewApp() *App {94 func NewApp() *App {
96 // Initialize AppConfig95 // Initialize AppConfig
97- config, err := LoadConfig()96+ config, err := LoadConfig(AppConfig{})
97+ fmt.Printf("Config: %+v\n", config)
98 if err != nil {98 if err != nil {
99 log.Fatalf("Failed to load configuration: %v", err)99 log.Fatalf("Failed to load configuration: %v", err)
100 }100 }
@@ -117,7 +117,7 @@ func NewApp() *App {
117 a := &App{117 a := &App{
118 TemplateFS: templates.TemplateFS,118 TemplateFS: templates.TemplateFS,
119 PublicFS: webui.PublicFS,119 PublicFS: webui.PublicFS,
120- StringsYML: bytes,120+ LocYML: bytes,
121 DBDir: DBDir,121 DBDir: DBDir,
122 DBFilename: DBFilename,122 DBFilename: DBFilename,
123 Config: config,123 Config: config,
M internal/httpserve/handler/createcontainer.go +1 -1
@@ -106,7 +106,7 @@ func CreateContainerPOST(c echo.Context, a *app.App) error {
106106 }
107107 }
108108
109- cmdParams, err := render.FromInputsToCmdParams(sanitizedInputs)
109+ cmdParams, err := render.FromInputsToCmdParams(sanitizedInputs, a)
110110 if err != nil {
111111 return sendError(c, err)
112112 }
@@ -106,7 +106,7 @@ func CreateContainerPOST(c echo.Context, a *app.App) error {
106 }106 }
107 }107 }
108 108
109- cmdParams, err := render.FromInputsToCmdParams(sanitizedInputs)109+ cmdParams, err := render.FromInputsToCmdParams(sanitizedInputs, a)
110 if err != nil {110 if err != nil {
111 return sendError(c, err)111 return sendError(c, err)
112 }112 }
M internal/templates/render/cmdparams.go +3 -2
@@ -4,11 +4,12 @@ import (
44 "fmt"
55 "strings"
66
7+ "github.com/bnema/gordon/internal/app"
78 "github.com/bnema/gordon/pkg/docker"
89 )
910
1011 // FromInputsToCmdParams transforms the inputs map into a ContainerCommandParams struct
11-func FromInputsToCmdParams(inputs map[string]string) (docker.ContainerCommandParams, error) {
12+func FromInputsToCmdParams(inputs map[string]string, a *app.App) (docker.ContainerCommandParams, error) {
1213
1314 volumeStr := inputs["volumes"]
1415 volumeSlice := strings.Split(volumeStr, ",")
@@ -45,7 +46,7 @@ func FromInputsToCmdParams(inputs map[string]string) (docker.ContainerCommandPar
4546 Restart: inputs["restart"],
4647 Volumes: volumeSlice,
4748 Environment: environmentSlice,
48- Network: ("traefik"),
49+ Network: a.Config.ContainerEngine.Network,
4950 PortMappings: portMappings,
5051 }
5152
@@ -4,11 +4,12 @@ import (
4 "fmt"4 "fmt"
5 "strings"5 "strings"
6 6
7+ "github.com/bnema/gordon/internal/app"
7 "github.com/bnema/gordon/pkg/docker"8 "github.com/bnema/gordon/pkg/docker"
8 )9 )
9 10
10 // FromInputsToCmdParams transforms the inputs map into a ContainerCommandParams struct11 // FromInputsToCmdParams transforms the inputs map into a ContainerCommandParams struct
11-func FromInputsToCmdParams(inputs map[string]string) (docker.ContainerCommandParams, error) {12+func FromInputsToCmdParams(inputs map[string]string, a *app.App) (docker.ContainerCommandParams, error) {
12 13
13 volumeStr := inputs["volumes"]14 volumeStr := inputs["volumes"]
14 volumeSlice := strings.Split(volumeStr, ",")15 volumeSlice := strings.Split(volumeStr, ",")
@@ -45,7 +46,7 @@ func FromInputsToCmdParams(inputs map[string]string) (docker.ContainerCommandPar
45 Restart: inputs["restart"],46 Restart: inputs["restart"],
46 Volumes: volumeSlice,47 Volumes: volumeSlice,
47 Environment: environmentSlice,48 Environment: environmentSlice,
48- Network: ("traefik"),49+ Network: a.Config.ContainerEngine.Network,
49 PortMappings: portMappings,50 PortMappings: portMappings,
50 }51 }
51 52
M internal/templates/render/localization.go +1 -1
@@ -41,7 +41,7 @@ func GetLocalization(lang string, a *app.App) (map[string]interface{}, error) {
4141 func getLocalizations(a *app.App) (Localizations, error) {
4242 var loc Localizations
4343
44- err := yaml.Unmarshal(a.StringsYML, &loc)
44+ err := yaml.Unmarshal(a.LocYML, &loc)
4545 if err != nil {
4646 return loc, fmt.Errorf("failed to unmarshal strings.yml: %w", err)
4747 }
@@ -41,7 +41,7 @@ func GetLocalization(lang string, a *app.App) (map[string]interface{}, error) {
41 func getLocalizations(a *app.App) (Localizations, error) {41 func getLocalizations(a *app.App) (Localizations, error) {
42 var loc Localizations42 var loc Localizations
43 43
44- err := yaml.Unmarshal(a.StringsYML, &loc)44+ err := yaml.Unmarshal(a.LocYML, &loc)
45 if err != nil {45 if err != nil {
46 return loc, fmt.Errorf("failed to unmarshal strings.yml: %w", err)46 return loc, fmt.Errorf("failed to unmarshal strings.yml: %w", err)
47 }47 }

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