From e87f14bcbf7184f4e9ecc3b8dac0b6a2852b2c57 Mon Sep 17 00:00:00 2001 From: Maximilian Date: Sun, 3 Sep 2023 15:56:35 -0500 Subject: [PATCH] Make all slog errors uniform (lowercase) --- config/config.go | 6 +++--- database/connection.go | 2 +- database/migrate.go | 18 +++++++++--------- main.go | 12 ++++++------ routes/get.go | 2 +- security/csrf.go | 4 ++-- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/config/config.go b/config/config.go index 19c39e2..a107b28 100644 --- a/config/config.go +++ b/config/config.go @@ -33,13 +33,13 @@ func LoadConfig() Configuration { flag.Parse() file, err := os.Open(*c) if err != nil { - panic("Unable to open JSON config file: " + err.Error()) + panic("unable to open JSON config file: " + err.Error()) } defer func(file *os.File) { err := file.Close() if err != nil { - slog.Error("Unable to close JSON config file: ", err) + slog.Error("unable to close JSON config file: ", err) } }(file) @@ -47,7 +47,7 @@ func LoadConfig() Configuration { Config := Configuration{} err = decoder.Decode(&Config) if err != nil { - panic("Unable to decode JSON config file: " + err.Error()) + panic("unable to decode JSON config file: " + err.Error()) } return Config diff --git a/database/connection.go b/database/connection.go index 12315db..3978599 100644 --- a/database/connection.go +++ b/database/connection.go @@ -24,7 +24,7 @@ func Connect(app *app.App) *sql.DB { panic(err) } - slog.Info("Connected to database successfully on " + app.Config.Db.Ip + ":" + app.Config.Db.Port + " using database " + app.Config.Db.Name) + slog.Info("connected to database successfully on " + app.Config.Db.Ip + ":" + app.Config.Db.Port + " using database " + app.Config.Db.Name) return db } diff --git a/database/migrate.go b/database/migrate.go index e859d51..d45f7ce 100644 --- a/database/migrate.go +++ b/database/migrate.go @@ -39,23 +39,23 @@ func createTable(app *app.App, tableName string) error { var tableExists bool err := app.Db.QueryRow("SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relname ~ $1 AND pg_catalog.pg_table_is_visible(c.oid))", "^"+tableName+"$").Scan(&tableExists) if err != nil { - slog.Error("Error checking if table exists: " + tableName) + slog.Error("error checking if table exists: " + tableName) return err } if tableExists { - slog.Info("Table already exists: " + tableName) + slog.Info("table already exists: " + tableName) return nil } else { sanitizedTableQuery := fmt.Sprintf("CREATE TABLE IF NOT EXISTS \"%s\" (\"Id\" serial primary key)", tableName) _, err := app.Db.Query(sanitizedTableQuery) if err != nil { - slog.Error("Error creating table: " + tableName) + slog.Error("error creating table: " + tableName) return err } - slog.Info("Table created successfully: " + tableName) + slog.Info("table created successfully: " + tableName) return nil } } @@ -65,17 +65,17 @@ func createColumn(app *app.App, tableName, columnName, columnType string) error var columnExists bool err := app.Db.QueryRow("SELECT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = $1 AND column_name = $2)", tableName, columnName).Scan(&columnExists) if err != nil { - slog.Error("Error checking if column exists: " + columnName + " in table: " + tableName) + slog.Error("error checking if column exists: " + columnName + " in table: " + tableName) return err } if columnExists { - slog.Info("Column already exists: " + columnName + " in table: " + tableName) + slog.Info("column already exists: " + columnName + " in table: " + tableName) return nil } else { postgresType, err := getPostgresType(columnType) if err != nil { - slog.Error("Error creating column: " + columnName + " in table: " + tableName + " with type: " + postgresType) + slog.Error("error creating column: " + columnName + " in table: " + tableName + " with type: " + postgresType) return err } @@ -84,11 +84,11 @@ func createColumn(app *app.App, tableName, columnName, columnType string) error _, err = app.Db.Query(query) if err != nil { - slog.Error("Error creating column: " + columnName + " in table: " + tableName + " with type: " + postgresType) + slog.Error("error creating column: " + columnName + " in table: " + tableName + " with type: " + postgresType) return err } - slog.Info("Column created successfully:", columnName) + slog.Info("column created successfully:", columnName) return nil } diff --git a/main.go b/main.go index 83dbb2a..c546878 100644 --- a/main.go +++ b/main.go @@ -34,14 +34,14 @@ func main() { if _, err := os.Stat("logs"); os.IsNotExist(err) { err := os.Mkdir("logs", 0755) if err != nil { - panic("Failed to create log directory: " + err.Error()) + panic("failed to create log directory: " + err.Error()) } } // Create log file and set output file, err := os.OpenFile("logs/"+time.Now().Format("2006-01-02")+".log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644) if err != nil { - panic("Error creating log file: " + err.Error()) + panic("error creating log file: " + err.Error()) } logger := slog.New(slog.NewTextHandler(file, nil)) @@ -70,10 +70,10 @@ func main() { // Start server server := &http.Server{Addr: appLoaded.Config.Listen.Ip + ":" + appLoaded.Config.Listen.Port} go func() { - slog.Info("Starting server and listening on " + appLoaded.Config.Listen.Ip + ":" + appLoaded.Config.Listen.Port) + slog.Info("starting server and listening on " + appLoaded.Config.Listen.Ip + ":" + appLoaded.Config.Listen.Port) err := server.ListenAndServe() if err != nil && !errors.Is(err, http.ErrServerClosed) { - slog.Error("Could not listen on %s: %v\n", appLoaded.Config.Listen.Ip+":"+appLoaded.Config.Listen.Port, err) + slog.Error("could not listen on %s: %v\n", appLoaded.Config.Listen.Ip+":"+appLoaded.Config.Listen.Port, err) os.Exit(1) } }() @@ -85,11 +85,11 @@ func main() { go app.RunScheduledTasks(&appLoaded, 100, stop) <-interrupt - slog.Info("Interrupt signal received. Shutting down server...") + slog.Info("interrupt signal received. Shutting down server...") err = server.Shutdown(context.Background()) if err != nil { - slog.Error("Could not gracefully shutdown the server: %v\n", err) + slog.Error("could not gracefully shutdown the server: %v\n", err) os.Exit(1) } } diff --git a/routes/get.go b/routes/get.go index 0109773..5282fb8 100644 --- a/routes/get.go +++ b/routes/get.go @@ -23,7 +23,7 @@ func Get(app *app.App) { } staticHandler := http.FileServer(http.FS(staticFS)) http.Handle("/static/", http.StripPrefix("/static/", staticHandler)) - slog.Info("Serving static files from embedded file system /static") + slog.Info("serving static files from embedded file system /static") // Pages http.HandleFunc("/", getController.ShowHome) diff --git a/security/csrf.go b/security/csrf.go index 6be63d9..4d81a00 100644 --- a/security/csrf.go +++ b/security/csrf.go @@ -13,7 +13,7 @@ func GenerateCsrfToken(w http.ResponseWriter, _ *http.Request) (string, error) { buff := make([]byte, int(math.Ceil(float64(64)/2))) _, err := rand.Read(buff) if err != nil { - slog.Error("Error creating random buffer for csrf token value" + err.Error()) + slog.Error("error creating random buffer for csrf token value" + err.Error()) return "", err } str := hex.EncodeToString(buff) @@ -37,7 +37,7 @@ func GenerateCsrfToken(w http.ResponseWriter, _ *http.Request) (string, error) { func VerifyCsrfToken(r *http.Request) (bool, error) { cookie, err := r.Cookie("csrf_token") if err != nil { - slog.Info("Unable to get csrf_token cookie" + err.Error()) + slog.Info("unable to get csrf_token cookie" + err.Error()) return false, err }