From 0c17486015545a8bebb8e24fb7449f9825ba2556 Mon Sep 17 00:00:00 2001 From: Fabio Scotto di Santolo Date: Sun, 1 Jun 2025 13:00:00 +0200 Subject: [PATCH] Fix configurations --- .gitignore | 43 ++++++++++++++-------------- .idea/.gitignore | 10 ------- .idea/codeStyles/Project.xml | 7 ----- .idea/codeStyles/codeStyleConfig.xml | 5 ---- .idea/git_toolbox_prj.xml | 15 ---------- .idea/misc.xml | 6 ---- .idea/modules.xml | 8 ------ .idea/vcs.xml | 6 ---- cmd/fileserver/main.go | 4 +-- config/application-dev.json | 2 +- config/application.json | 2 +- config/config.go | 13 +++++---- 12 files changed, 33 insertions(+), 88 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/codeStyles/Project.xml delete mode 100644 .idea/codeStyles/codeStyleConfig.xml delete mode 100644 .idea/git_toolbox_prj.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore index ef40fab..1b0af02 100644 --- a/.gitignore +++ b/.gitignore @@ -3,30 +3,30 @@ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 # User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf +# .idea/**/workspace.xml +# .idea/**/tasks.xml +# .idea/**/usage.statistics.xml +# .idea/**/dictionaries +# .idea/**/shelf # AWS User-specific -.idea/**/aws.xml +# .idea/**/aws.xml # Generated files -.idea/**/contentModel.xml +# .idea/**/contentModel.xml # Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml +# .idea/**/dataSources/ +# .idea/**/dataSources.ids +# .idea/**/dataSources.local.xml +# .idea/**/sqlDataSources.xml +# .idea/**/dynamic.xml +# .idea/**/uiDesigner.xml +# .idea/**/dbnavigator.xml # Gradle -.idea/**/gradle.xml -.idea/**/libraries +# .idea/**/gradle.xml +# .idea/**/libraries # Gradle and Maven with auto-import # When using Gradle or Maven with auto-import, you should exclude module files, @@ -38,6 +38,7 @@ # .idea/modules.xml # .idea/*.iml # .idea/modules +.idea *.iml *.ipr @@ -45,7 +46,7 @@ cmake-build-*/ # Mongo Explorer plugin -.idea/**/mongoSettings.xml +#.idea/**/mongoSettings.xml # File-based project format *.iws @@ -60,10 +61,10 @@ out/ atlassian-ide-plugin.xml # Cursive Clojure plugin -.idea/replstate.xml +#.idea/replstate.xml # SonarLint plugin -.idea/sonarlint/ +#.idea/sonarlint/ # Crashlytics plugin (for Android Studio and IntelliJ) com_crashlytics_export_strings.xml @@ -72,10 +73,10 @@ crashlytics-build.properties fabric.properties # Editor-based Rest Client -.idea/httpRequests +#.idea/httpRequests # Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser +# .idea/caches/build_file_checksums.ser ### Linux template *~ diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 18d7b81..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Environment-dependent path to Maven home directory -/mavenHomeManager.xml -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index c2621b8..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml deleted file mode 100644 index df5f35d..0000000 --- a/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/git_toolbox_prj.xml b/.idea/git_toolbox_prj.xml deleted file mode 100644 index 02b915b..0000000 --- a/.idea/git_toolbox_prj.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 9715c22..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index d4c7d02..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/cmd/fileserver/main.go b/cmd/fileserver/main.go index 3f062a0..e7c6777 100644 --- a/cmd/fileserver/main.go +++ b/cmd/fileserver/main.go @@ -22,14 +22,14 @@ func main() { log.Fatalf("Error to read %s configuration: %v\n", profile, err) } log.Printf("Application starting with profile: %s", profile) - server := config.App.Server - mux := http.NewServeMux() // Register all routes in the new ServeMux + mux := http.NewServeMux() log.Printf("Register all routes\n") for url, handler := range api.Routes { log.Printf("Register route %s for %v", url, getFunctionName(handler)) mux.HandleFunc(url, handler) } + server := config.App.Server url := fmt.Sprintf("%s:%d", server.Host, server.Port) log.Printf("Start server on %s\n", url) if err := http.ListenAndServe(url, mux); err != nil { diff --git a/config/application-dev.json b/config/application-dev.json index f6787bc..e61ddd9 100644 --- a/config/application-dev.json +++ b/config/application-dev.json @@ -1,6 +1,6 @@ { "server": { "host": "localhost", - "port": 8080 + "port": 8081 } } diff --git a/config/application.json b/config/application.json index 26decab..f6787bc 100644 --- a/config/application.json +++ b/config/application.json @@ -1,6 +1,6 @@ { "server": { "host": "localhost", - "port": 8089 + "port": 8080 } } diff --git a/config/config.go b/config/config.go index 7f09972..43f5b87 100644 --- a/config/config.go +++ b/config/config.go @@ -3,7 +3,6 @@ package config import ( "encoding/json" "fmt" - "log" "os" ) @@ -21,19 +20,21 @@ var App Application const configDir = "config" func Initialize(profile string) error { - filename := checkProfileAndGetFilePath(profile) + filename, err := checkProfileAndGetFilePath(profile) + if err != nil { + return fmt.Errorf("errore checking profile: %v", err) + } content, err := os.ReadFile(filename) if err != nil { return fmt.Errorf("error reading file: %v", err) } - if err = json.Unmarshal(content, &App); err != nil { return fmt.Errorf("error unmarshaling JSON: %v", err) } return nil } -func checkProfileAndGetFilePath(profile string) string { +func checkProfileAndGetFilePath(profile string) (string, error) { var filename string switch { case profile == "dev": @@ -43,7 +44,7 @@ func checkProfileAndGetFilePath(profile string) string { case profile == "prod": filename = fmt.Sprintf("%s/application.json", configDir) default: - log.Fatalf("Profile %s is not valid value", profile) + return "", fmt.Errorf("profile %s is not valid value", profile) } - return filename + return filename, nil }