diff --git a/controllers/getController.go b/controllers/getController.go index c74b073..6a80e15 100644 --- a/controllers/getController.go +++ b/controllers/getController.go @@ -13,7 +13,7 @@ type GetController struct { App *app.App } -func (getController *GetController) ShowHome(w http.ResponseWriter, r *http.Request) { +func (getController *GetController) ShowHome(w http.ResponseWriter, _ *http.Request) { type dataStruct struct { Test string } @@ -27,17 +27,17 @@ func (getController *GetController) ShowHome(w http.ResponseWriter, r *http.Requ func (getController *GetController) ShowRegister(w http.ResponseWriter, r *http.Request) { type dataStruct struct { - csrf_token string + csrfToken string } // Create csrf token - csrf_token, err := security.GenerateCsrfToken(w, r) + csrfToken, err := security.GenerateCsrfToken(w, r) if err != nil { return } data := dataStruct{ - csrf_token: csrf_token, + csrfToken: csrfToken, } templating.RenderTemplate(getController.App, w, "templates/pages/register.html", data) @@ -45,17 +45,17 @@ func (getController *GetController) ShowRegister(w http.ResponseWriter, r *http. func (getController *GetController) ShowLogin(w http.ResponseWriter, r *http.Request) { type dataStruct struct { - csrf_token string + csrfToken string } // Create csrf token - csrf_token, err := security.GenerateCsrfToken(w, r) + csrfToken, err := security.GenerateCsrfToken(w, r) if err != nil { return } data := dataStruct{ - csrf_token: csrf_token, + csrfToken: csrfToken, } templating.RenderTemplate(getController.App, w, "templates/pages/login.html", data) diff --git a/main.go b/main.go index 4ea4d4a..2d81e63 100644 --- a/main.go +++ b/main.go @@ -8,34 +8,38 @@ import ( "log" "net/http" "os" + "time" ) func main() { // Create instance of App - app := app.App{} + appLoaded := app.App{} // Load config file to application - app.Config = config.LoadConfig() + appLoaded.Config = config.LoadConfig() // Create logs directory if it doesn't exist if _, err := os.Stat("logs"); os.IsNotExist(err) { - os.Mkdir("logs", 0755) + err := os.Mkdir("logs", 0755) + if err != nil { + panic("Failed to create log directory") + } } // Create log file and set output - //file, _ := os.Create("logs/log-" + time.Now().String() + ".log") - //log.SetOutput(file) + file, _ := os.Create("logs/log-" + time.Now().String() + ".log") + log.SetOutput(file) // Connect to database - app.Db = database.ConnectDB(&app) + appLoaded.Db = database.ConnectDB(&appLoaded) // Define Routes - routes.GetRoutes(&app) - routes.PostRoutes(&app) + routes.GetRoutes(&appLoaded) + routes.PostRoutes(&appLoaded) // Start server - log.Println("Starting server and listening on " + app.Config.Listen.Ip + ":" + app.Config.Listen.Port) - err := http.ListenAndServe(app.Config.Listen.Ip+":"+app.Config.Listen.Port, nil) + log.Println("Starting server and listening on " + appLoaded.Config.Listen.Ip + ":" + appLoaded.Config.Listen.Port) + err := http.ListenAndServe(appLoaded.Config.Listen.Ip+":"+appLoaded.Config.Listen.Port, nil) if err != nil { log.Println(err) return diff --git a/security/csrf.go b/security/csrf.go index f541e64..91a0282 100644 --- a/security/csrf.go +++ b/security/csrf.go @@ -9,7 +9,7 @@ import ( ) // GenerateCsrfToken generates a csrf token and assigns it to a cookie for double submit cookie csrf protection -func GenerateCsrfToken(w http.ResponseWriter, r *http.Request) (string, error) { +func GenerateCsrfToken(w http.ResponseWriter, _ *http.Request) (string, error) { // Generate random 64 character string (alpha-numeric) buff := make([]byte, int(math.Ceil(float64(64)/2))) _, err := rand.Read(buff) diff --git a/templates/pages/login.html b/templates/pages/login.html index 6e30b33..7281027 100644 --- a/templates/pages/login.html +++ b/templates/pages/login.html @@ -2,7 +2,7 @@ {{ define "content" }}