detached 717e73e

Refactor Config structure, remove debug logs, update dev dependencies, and adjust affected functions

commit
717e73eb17a2a576f1cb9dd5b68a738375428a6f
author
bnema · · 2023-10-12 12:49 UTC
parent
45f9b86
signature
unsigned
4 files · +999 -16
M internal/app/app.go +12 -14
@@ -28,9 +28,9 @@ type App struct {
2828 DBPath string
2929 InitialChecksum string
3030 DB *sql.DB
31- Config AppConfig
31+ Config Config
3232 }
33-type AppConfig struct {
33+type Config struct {
3434 General GeneralConfig `yaml:"General"`
3535 Http HttpConfig `yaml:"Http"`
3636 Admin AdminConfig `yaml:"Admin"`
@@ -38,10 +38,11 @@ type AppConfig struct {
3838 }
3939
4040 type GeneralConfig struct {
41- RunEnv string
42- BuildDir string
43- BuildVersion string
41+ RunEnv string // come from env
42+ BuildDir string // come from env
43+ BuildVersion string // come from env
4444 StorageDir string `yaml:"storageDir"`
45+ GordonToken string `yaml:"gordonToken"`
4546 }
4647
4748 type HttpConfig struct {
@@ -61,7 +62,7 @@ type ContainerEngineConfig struct {
6162 Network string `yaml:"network"`
6263 }
6364
64-func LoadConfig(config AppConfig) (AppConfig, error) {
65+func LoadConfig(config *Config) (*Config, error) {
6566 // Load env elements
6667 config.General.BuildVersion = os.Getenv("BUILD_VERSION")
6768 config.General.RunEnv = os.Getenv("RUN_ENV")
@@ -72,10 +73,6 @@ func LoadConfig(config AppConfig) (AppConfig, error) {
7273 config.General.RunEnv = "prod"
7374 config.General.BuildDir = "."
7475 }
75-
76- fmt.Printf("RUN_ENV: %s\n", config.General.RunEnv)
77- fmt.Printf("BUILD_DIR: %s\n", config.General.BuildDir)
78-
7976 // Load config file
8077 configFile := fmt.Sprintf("%s/config.yml", config.General.BuildDir)
8178 configData, err := os.ReadFile(configFile)
@@ -93,7 +90,8 @@ func LoadConfig(config AppConfig) (AppConfig, error) {
9390
9491 func NewApp() *App {
9592 // Initialize AppConfig
96- config, err := LoadConfig(AppConfig{})
93+ config := &Config{}
94+ _, err := LoadConfig(config)
9795 if err != nil {
9896 log.Fatalf("Failed to load configuration: %v", err)
9997 }
@@ -119,7 +117,7 @@ func NewApp() *App {
119117 LocYML: bytes,
120118 DBDir: DBDir,
121119 DBFilename: DBFilename,
122- Config: config,
120+ Config: *config,
123121 }
124122
125123 OauthCallbackURL = config.GenerateOauthCallbackURL()
@@ -127,7 +125,7 @@ func NewApp() *App {
127125 }
128126
129127 // NewDockerConfig creates and returns a new Docker client configuration
130-func (config *AppConfig) NewDockerConfig() *docker.Config {
128+func (config *Config) NewDockerConfig() *docker.Config {
131129 if config.ContainerEngine.Podman {
132130 return &docker.Config{
133131 Sock: config.ContainerEngine.PodmanSock,
@@ -141,7 +139,7 @@ func (config *AppConfig) NewDockerConfig() *docker.Config {
141139 }
142140
143141 // GenerateOauthCallbackURL generates the OAuth callback URL
144-func (config *AppConfig) GenerateOauthCallbackURL() string {
142+func (config *Config) GenerateOauthCallbackURL() string {
145143 var scheme, port string
146144
147145 if config.General.RunEnv == "dev" {
@@ -28,9 +28,9 @@ type App struct {
28 DBPath string28 DBPath string
29 InitialChecksum string29 InitialChecksum string
30 DB *sql.DB30 DB *sql.DB
31- Config AppConfig31+ Config Config
32 }32 }
33-type AppConfig struct {33+type Config struct {
34 General GeneralConfig `yaml:"General"`34 General GeneralConfig `yaml:"General"`
35 Http HttpConfig `yaml:"Http"`35 Http HttpConfig `yaml:"Http"`
36 Admin AdminConfig `yaml:"Admin"`36 Admin AdminConfig `yaml:"Admin"`
@@ -38,10 +38,11 @@ type AppConfig struct {
38 }38 }
39 39
40 type GeneralConfig struct {40 type GeneralConfig struct {
41- RunEnv string41+ RunEnv string // come from env
42- BuildDir string42+ BuildDir string // come from env
43- BuildVersion string43+ BuildVersion string // come from env
44 StorageDir string `yaml:"storageDir"`44 StorageDir string `yaml:"storageDir"`
45+ GordonToken string `yaml:"gordonToken"`
45 }46 }
46 47
47 type HttpConfig struct {48 type HttpConfig struct {
@@ -61,7 +62,7 @@ type ContainerEngineConfig struct {
61 Network string `yaml:"network"`62 Network string `yaml:"network"`
62 }63 }
63 64
64-func LoadConfig(config AppConfig) (AppConfig, error) {65+func LoadConfig(config *Config) (*Config, error) {
65 // Load env elements66 // Load env elements
66 config.General.BuildVersion = os.Getenv("BUILD_VERSION")67 config.General.BuildVersion = os.Getenv("BUILD_VERSION")
67 config.General.RunEnv = os.Getenv("RUN_ENV")68 config.General.RunEnv = os.Getenv("RUN_ENV")
@@ -72,10 +73,6 @@ func LoadConfig(config AppConfig) (AppConfig, error) {
72 config.General.RunEnv = "prod"73 config.General.RunEnv = "prod"
73 config.General.BuildDir = "."74 config.General.BuildDir = "."
74 }75 }
75-
76- fmt.Printf("RUN_ENV: %s\n", config.General.RunEnv)
77- fmt.Printf("BUILD_DIR: %s\n", config.General.BuildDir)
78-
79 // Load config file76 // Load config file
80 configFile := fmt.Sprintf("%s/config.yml", config.General.BuildDir)77 configFile := fmt.Sprintf("%s/config.yml", config.General.BuildDir)
81 configData, err := os.ReadFile(configFile)78 configData, err := os.ReadFile(configFile)
@@ -93,7 +90,8 @@ func LoadConfig(config AppConfig) (AppConfig, error) {
93 90
94 func NewApp() *App {91 func NewApp() *App {
95 // Initialize AppConfig92 // Initialize AppConfig
96- config, err := LoadConfig(AppConfig{})93+ config := &Config{}
94+ _, err := LoadConfig(config)
97 if err != nil {95 if err != nil {
98 log.Fatalf("Failed to load configuration: %v", err)96 log.Fatalf("Failed to load configuration: %v", err)
99 }97 }
@@ -119,7 +117,7 @@ func NewApp() *App {
119 LocYML: bytes,117 LocYML: bytes,
120 DBDir: DBDir,118 DBDir: DBDir,
121 DBFilename: DBFilename,119 DBFilename: DBFilename,
122- Config: config,120+ Config: *config,
123 }121 }
124 122
125 OauthCallbackURL = config.GenerateOauthCallbackURL()123 OauthCallbackURL = config.GenerateOauthCallbackURL()
@@ -127,7 +125,7 @@ func NewApp() *App {
127 }125 }
128 126
129 // NewDockerConfig creates and returns a new Docker client configuration127 // NewDockerConfig creates and returns a new Docker client configuration
130-func (config *AppConfig) NewDockerConfig() *docker.Config {128+func (config *Config) NewDockerConfig() *docker.Config {
131 if config.ContainerEngine.Podman {129 if config.ContainerEngine.Podman {
132 return &docker.Config{130 return &docker.Config{
133 Sock: config.ContainerEngine.PodmanSock,131 Sock: config.ContainerEngine.PodmanSock,
@@ -141,7 +139,7 @@ func (config *AppConfig) NewDockerConfig() *docker.Config {
141 }139 }
142 140
143 // GenerateOauthCallbackURL generates the OAuth callback URL141 // GenerateOauthCallbackURL generates the OAuth callback URL
144-func (config *AppConfig) GenerateOauthCallbackURL() string {142+func (config *Config) GenerateOauthCallbackURL() string {
145 var scheme, port string143 var scheme, port string
146 144
147 if config.General.RunEnv == "dev" {145 if config.General.RunEnv == "dev" {
A package-lock.json +983 -0 generated file: collapsed
M package.json +2 -0
@@ -1,6 +1,8 @@
11 {
22 "devDependencies": {
33 "@catppuccin/tailwindcss": "^0.1.6",
4+ "prettier": "^3.0.3",
5+ "prettier-plugin-tailwindcss": "^0.5.5",
46 "tailwindcss": "^3.3.3"
57 },
68 "scripts": {
@@ -1,6 +1,8 @@
1 {1 {
2 "devDependencies": {2 "devDependencies": {
3 "@catppuccin/tailwindcss": "^0.1.6",3 "@catppuccin/tailwindcss": "^0.1.6",
4+ "prettier": "^3.0.3",
5+ "prettier-plugin-tailwindcss": "^0.5.5",
4 "tailwindcss": "^3.3.3"6 "tailwindcss": "^3.3.3"
5 },7 },
6 "scripts": {8 "scripts": {
M pkg/store/storeimages.go +2 -2
@@ -17,13 +17,13 @@ type StorageConfig struct {
1717 Images []types.ImageSummary
1818 }
1919
20-func NewStorageConfig(config *app.AppConfig) *StorageConfig {
20+func NewStorageConfig(config *app.Config) *StorageConfig {
2121 return &StorageConfig{
2222 StorageDir: config.General.StorageDir,
2323 }
2424 }
2525
26-func SaveImageToStorage(config *app.AppConfig, filename string, buf io.Reader) (string, error) {
26+func SaveImageToStorage(config *app.Config, filename string, buf io.Reader) (string, error) {
2727 // Check if the folder exist if not create it
2828 if _, err := os.Stat(config.General.StorageDir); os.IsNotExist(err) {
2929 err := os.MkdirAll(config.General.StorageDir, 0755)
@@ -17,13 +17,13 @@ type StorageConfig struct {
17 Images []types.ImageSummary17 Images []types.ImageSummary
18 }18 }
19 19
20-func NewStorageConfig(config *app.AppConfig) *StorageConfig {20+func NewStorageConfig(config *app.Config) *StorageConfig {
21 return &StorageConfig{21 return &StorageConfig{
22 StorageDir: config.General.StorageDir,22 StorageDir: config.General.StorageDir,
23 }23 }
24 }24 }
25 25
26-func SaveImageToStorage(config *app.AppConfig, filename string, buf io.Reader) (string, error) {26+func SaveImageToStorage(config *app.Config, filename string, buf io.Reader) (string, error) {
27 // Check if the folder exist if not create it27 // Check if the folder exist if not create it
28 if _, err := os.Stat(config.General.StorageDir); os.IsNotExist(err) {28 if _, err := os.Stat(config.General.StorageDir); os.IsNotExist(err) {
29 err := os.MkdirAll(config.General.StorageDir, 0755)29 err := os.MkdirAll(config.General.StorageDir, 0755)

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