diff --git a/server/controllers/auth.go b/server/controllers/auth.go index b130739..56f1bf6 100644 --- a/server/controllers/auth.go +++ b/server/controllers/auth.go @@ -94,17 +94,17 @@ func userLogin(c *gin.Context) { user, err := db.FindOneUser(&db.User{Email: loginRequest.Email}) if err != nil { - c.JSON(http.StatusForbidden, common.NewError("login", errors.New("Not Registered email or invalid password"))) + c.JSON(http.StatusForbidden, common.NewError("login", errors.New("not Registered email or invalid password"))) return } if user.CheckPassword(loginRequest.Password) != nil { - c.JSON(http.StatusForbidden, common.NewError("login", errors.New("Not Registered email or invalid password"))) + c.JSON(http.StatusForbidden, common.NewError("login", errors.New("not Registered email or invalid password"))) return } if user.IsDisabled { - c.JSON(http.StatusForbidden, common.NewError("login", errors.New("Your user has been disabled by the admin. Please contact them to get it re-enabled."))) + c.JSON(http.StatusForbidden, common.NewError("login", errors.New("your user has been disabled by the admin. Please contact them to get it re-enabled"))) return } UpdateContextUserModel(c, user.ID) @@ -170,16 +170,16 @@ func changePassword(c *gin.Context) { user, err := service.GetUserById(c.GetString("userId")) if err != nil { - c.JSON(http.StatusForbidden, common.NewError("changePassword", errors.New("Not Registered email or invalid password"))) + c.JSON(http.StatusForbidden, common.NewError("changePassword", errors.New("not Registered email or invalid password"))) return } if user.CheckPassword(request.OldPassword) != nil { - c.JSON(http.StatusForbidden, common.NewError("changePassword", errors.New("Incorrect old password"))) + c.JSON(http.StatusForbidden, common.NewError("changePassword", errors.New("incorrect old password"))) return } user.SetPassword(request.NewPassword) - success, err := service.UpdatePassword(user.ID, request.NewPassword) + success, _ := service.UpdatePassword(user.ID, request.NewPassword) c.JSON(http.StatusOK, success) } diff --git a/server/controllers/middlewares.go b/server/controllers/middlewares.go index 3c12c54..6dfede7 100644 --- a/server/controllers/middlewares.go +++ b/server/controllers/middlewares.go @@ -23,8 +23,8 @@ func stripBearerPrefixFromTokenString(tok string) (string, error) { // Extract token from Authorization header // Uses PostExtractionFilter to strip "TOKEN " prefix from header var AuthorizationHeaderExtractor = &request.PostExtractionFilter{ - request.HeaderExtractor{"Authorization"}, - stripBearerPrefixFromTokenString, + Extractor: request.HeaderExtractor{"Authorization"}, + Filter: stripBearerPrefixFromTokenString, } // Extractor for OAuth2 access tokens. Looks in 'Authorization' diff --git a/server/controllers/setup.go b/server/controllers/setup.go index b8378f3..13f1ce3 100644 --- a/server/controllers/setup.go +++ b/server/controllers/setup.go @@ -51,7 +51,7 @@ func migrate(c *gin.Context) { canMigrate, _, _ := db.CanMigrate(request.Url) if !canMigrate { - c.JSON(http.StatusBadRequest, fmt.Errorf("cannot migrate database. please check connection string.")) + c.JSON(http.StatusBadRequest, fmt.Errorf("cannot migrate database. please check connection string")) return } diff --git a/server/controllers/vehicle.go b/server/controllers/vehicle.go index d914b7c..a2c0f32 100644 --- a/server/controllers/vehicle.go +++ b/server/controllers/vehicle.go @@ -397,7 +397,7 @@ func deleteVehicle(c *gin.Context) { return } if !canDelete { - c.JSON(http.StatusUnprocessableEntity, common.NewError("shareVehicle", errors.New("You are not allowed to delete this vehicle."))) + c.JSON(http.StatusUnprocessableEntity, common.NewError("shareVehicle", errors.New("you are not allowed to delete this vehicle"))) return } err = service.DeleteVehicle(searchByIdQuery.Id) diff --git a/server/db/dbfunctions.go b/server/db/dbfunctions.go index ead5d10..31e0d42 100644 --- a/server/db/dbfunctions.go +++ b/server/db/dbfunctions.go @@ -117,7 +117,7 @@ func UnshareVehicle(vehicleId, userId string) error { return nil } if mapping.IsOwner { - return fmt.Errorf("Cannot unshare owner") + return fmt.Errorf("cannot unshare owner") } result := DB.Where("id=?", mapping.ID).Delete(&UserVehicle{}) return result.Error @@ -365,8 +365,7 @@ func UnlockMissedJobs() { if (job.Date == time.Time{}) { continue } - var duration time.Duration - duration = time.Duration(job.Duration) + var duration = time.Duration(job.Duration) d := job.Date.Add(time.Minute * duration) if d.Before(time.Now()) { fmt.Println(job.Name + " is unlocked") diff --git a/server/service/fileService.go b/server/service/fileService.go index c2d40c8..423171e 100644 --- a/server/service/fileService.go +++ b/server/service/fileService.go @@ -3,7 +3,6 @@ package service import ( "archive/tar" "compress/gzip" - "errors" "fmt" "io" "net/http" @@ -126,14 +125,14 @@ func CreateBackup() (string, error) { tarballFilePath := path.Join(folder, backupFileName) file, err := os.Create(tarballFilePath) if err != nil { - return "", errors.New(fmt.Sprintf("Could not create tarball file '%s', got error '%s'", tarballFilePath, err.Error())) + return "", fmt.Errorf("could not create tarball file '%s', got error '%s'", tarballFilePath, err.Error()) } defer file.Close() dbPath := path.Join(configPath, "hammond.db") _, err = os.Stat(dbPath) if err != nil { - return "", errors.New(fmt.Sprintf("Could not find db file '%s', got error '%s'", dbPath, err.Error())) + return "", fmt.Errorf("could not find db file '%s', got error '%s'", dbPath, err.Error()) } gzipWriter := gzip.NewWriter(file) defer gzipWriter.Close() @@ -151,13 +150,13 @@ func CreateBackup() (string, error) { func addFileToTarWriter(filePath string, tarWriter *tar.Writer) error { file, err := os.Open(filePath) if err != nil { - return errors.New(fmt.Sprintf("Could not open file '%s', got error '%s'", filePath, err.Error())) + return fmt.Errorf("could not open file '%s', got error '%s'", filePath, err.Error()) } defer file.Close() stat, err := file.Stat() if err != nil { - return errors.New(fmt.Sprintf("Could not get stat for file '%s', got error '%s'", filePath, err.Error())) + return fmt.Errorf("could not get stat for file '%s', got error '%s'", filePath, err.Error()) } header := &tar.Header{ @@ -169,12 +168,12 @@ func addFileToTarWriter(filePath string, tarWriter *tar.Writer) error { err = tarWriter.WriteHeader(header) if err != nil { - return errors.New(fmt.Sprintf("Could not write header for file '%s', got error '%s'", filePath, err.Error())) + return fmt.Errorf("could not write header for file '%s', got error '%s'", filePath, err.Error()) } _, err = io.Copy(tarWriter, file) if err != nil { - return errors.New(fmt.Sprintf("Could not copy the file '%s' data to the tarball, got error '%s'", filePath, err.Error())) + return fmt.Errorf("could not copy the file '%s' data to the tarball, got error '%s'", filePath, err.Error()) } return nil