diff --git a/config/config.go b/config/config.go index c284627..aff4667 100644 --- a/config/config.go +++ b/config/config.go @@ -68,13 +68,13 @@ type Config struct { func ReadConfigFile(filename string, conf *Config) error { configData, err := ioutil.ReadFile(filename) if err != nil { - err = fmt.Errorf("Error reading config file: %w", err) + err = fmt.Errorf("error reading config file: %w", err) log.Println(err.Error()) return err } err = json.Unmarshal(configData, conf) if err != nil { - err = fmt.Errorf("Error parsing config file as json: %w", err) + err = fmt.Errorf("error parsing config file as json: %w", err) log.Println(err.Error()) return err } @@ -85,66 +85,66 @@ func ReadConfigFile(filename string, conf *Config) error { func validateConfig(conf *Config) error { var err error if !(conf.Server.ListenPort >= 1 && conf.Server.ListenPort <= 65535) { - err = fmt.Errorf("Validating config: Server port must be between 1 and 65535, but is %d.", conf.Server.ListenPort) + err = fmt.Errorf("validating config: Server port must be between 1 and 65535, but is %d.", conf.Server.ListenPort) log.Println(err.Error()) } if !(conf.Server.Protocol == "http" || conf.Server.Protocol == "https") { - err = fmt.Errorf("Validating config: Server protocol must be 'http' or 'https', but is '%s'.", conf.Server.Protocol) + err = fmt.Errorf("validating config: Server protocol must be 'http' or 'https', but is '%s'.", conf.Server.Protocol) log.Println(err.Error()) } if !(conf.Date.MinuteGranularity >= 1 && conf.Date.MinuteGranularity <= 60) { - err = fmt.Errorf("Validating config: Minute granularity must be between 1 and 60, but is %d.", conf.Date.MinuteGranularity) + err = fmt.Errorf("validating config: Minute granularity must be between 1 and 60, but is %d.", conf.Date.MinuteGranularity) log.Println(err.Error()) } if !(conf.Date.EarliestStartTime.Hour >= 0 && conf.Date.EarliestStartTime.Hour <= 23) { - err = fmt.Errorf("Validating config: Earliest start time hour must be between 0 and 23, but is %d.", conf.Date.EarliestStartTime.Hour) + err = fmt.Errorf("validating config: Earliest start time hour must be between 0 and 23, but is %d.", conf.Date.EarliestStartTime.Hour) log.Println(err.Error()) } if !(conf.Date.EarliestStartTime.Minute >= 0 && conf.Date.EarliestStartTime.Minute <= 60) { - err = fmt.Errorf("Validating config: Earliest start time minute must be between 0 and 60, but is %d.", conf.Date.EarliestStartTime.Minute) + err = fmt.Errorf("validating config: Earliest start time minute must be between 0 and 60, but is %d.", conf.Date.EarliestStartTime.Minute) log.Println(err.Error()) } if !(conf.Date.MaxDuration >= conf.Date.MinuteGranularity && conf.Date.MaxDuration <= 4*60) { - err = fmt.Errorf("Validating config: Maximum duration must be between %d minute and 4 hours, but is %d.", conf.Date.MinuteGranularity, conf.Date.MaxDuration) + err = fmt.Errorf("validating config: Maximum duration must be between %d minute and 4 hours, but is %d.", conf.Date.MinuteGranularity, conf.Date.MaxDuration) log.Println(err.Error()) } if !(conf.Date.LatestStartTime.Hour >= 0 && conf.Date.LatestStartTime.Hour <= 23) { - err = fmt.Errorf("Validating config: Latest start time hour must be between 0 and 23, but is %d.", conf.Date.LatestStartTime.Hour) + err = fmt.Errorf("validating config: Latest start time hour must be between 0 and 23, but is %d.", conf.Date.LatestStartTime.Hour) log.Println(err.Error()) } if !(conf.Date.LatestStartTime.Minute >= 0 && conf.Date.LatestStartTime.Minute <= 60) { - err = fmt.Errorf("Validating config: Latest start time minute must be between 0 and 60, but is %d.", conf.Date.LatestStartTime.Minute) + err = fmt.Errorf("validating config: Latest start time minute must be between 0 and 60, but is %d.", conf.Date.LatestStartTime.Minute) log.Println(err.Error()) } if !(conf.Date.EarliestStartTime.Hour < conf.Date.LatestStartTime.Hour || (conf.Date.EarliestStartTime.Hour == conf.Date.LatestStartTime.Hour && conf.Date.EarliestStartTime.Minute < conf.Date.LatestStartTime.Minute)) { - err = fmt.Errorf("Validating config: Latest start time minute must be after earliest start time.") + err = fmt.Errorf("validating config: Latest start time minute must be after earliest start time.") log.Println(err.Error()) } if !(conf.Request.SecretLength >= 5 && conf.Request.SecretLength <= 50) { - err = fmt.Errorf("Validating config: Requests' secret length must be between 5 and 50, but is %d.", conf.Request.SecretLength) + err = fmt.Errorf("validating config: Requests' secret length must be between 5 and 50, but is %d.", conf.Request.SecretLength) log.Println(err.Error()) } if !(conf.Mailer.Type == "Stdout" || conf.Mailer.Type == "Smtp") { - err = fmt.Errorf("Validating config: Mailer type must be 'Stdout' or 'Smtp', but is '%s'.", conf.Mailer.Type) + err = fmt.Errorf("validating config: Mailer type must be 'Stdout' or 'Smtp', but is '%s'.", conf.Mailer.Type) log.Println(err.Error()) } mailFromAddress, mailFromAddressErr := mail.ParseAddress(conf.Mailer.FromAddress) if !(mailFromAddressErr == nil) { - err = fmt.Errorf("Validating config: Mail FromAddress could not be parsed (%w)", mailFromAddressErr) + err = fmt.Errorf("validating config: Mail FromAddress could not be parsed (%w)", mailFromAddressErr) log.Println(err) } else { if !(mailFromAddress.Name == "") { - err = fmt.Errorf("Validating config: Mail FromAddress must not contain a name value, but has '%s'", mailFromAddress.Name) + err = fmt.Errorf("validating config: Mail FromAddress must not contain a name value, but has '%s'", mailFromAddress.Name) log.Println(err) } } _, mailFromNameErr := mail.ParseAddress(string(conf.Mailer.FromName)) if !(mailFromNameErr == nil) { - err = fmt.Errorf("Validating config: Mail FromName could not be parsed (%w)", mailFromNameErr) + err = fmt.Errorf("validating config: Mail FromName could not be parsed (%w)", mailFromNameErr) log.Println(err) } if !(conf.SQL.Type == "SQLite" || conf.SQL.Type == "Mysql") { - err = fmt.Errorf("Validating config: SQL type must be 'SQLite' or 'Mysql', but is '%s'.", conf.SQL.Type) + err = fmt.Errorf("validating config: SQL type must be 'SQLite' or 'Mysql', but is '%s'.", conf.SQL.Type) log.Println(err.Error()) } return err diff --git a/repositories/course.go b/repositories/course.go index 7c2587d..62daa6d 100644 --- a/repositories/course.go +++ b/repositories/course.go @@ -30,7 +30,7 @@ func (r *CourseRepo) FindById(id int) (models.Course, error) { func (r *CourseRepo) GetAll() ([]models.Course, error) { rows, err := r.db.Query("SELECT * FROM course ORDER BY name ASC") if err != nil { - log.Printf("Error getting all courses: %s", err.Error()) + log.Printf("error getting all courses: %s", err.Error()) return nil, err } defer rows.Close() @@ -56,9 +56,9 @@ func (r *CourseRepo) getFromRows(rows *sql.Rows) ([]models.Course, error) { func (r *CourseRepo) getFromRow(row *sql.Row) (models.Course, error) { var course models.Course if err := row.Scan(&course.Id, &course.Name); err != nil { - err = fmt.Errorf("Error getting course row: %w", err) + err = fmt.Errorf("error getting course row: %w", err) if !errors.Is(err, sql.ErrNoRows) { - log.Printf(err.Error()) + log.Print(err.Error()) } return models.Course{}, err } diff --git a/repositories/officeHour.go b/repositories/officeHour.go index 7766896..27ccd86 100644 --- a/repositories/officeHour.go +++ b/repositories/officeHour.go @@ -37,7 +37,7 @@ func (r *OfficeHourRepo) GetAll(activeOnly bool) ([]models.OfficeHour, error) { rows, err = r.db.Query("SELECT * FROM officeHour") } if err != nil { - err = fmt.Errorf("Error getting all officeHours from database: %w", err) + err = fmt.Errorf("error getting all officeHours from database: %w", err) if !errors.Is(err, sql.ErrNoRows) { log.Println(err.Error()) } @@ -57,7 +57,7 @@ func (r *OfficeHourRepo) FindByCourse(course models.Course, activeOnly bool) ([] } defer rows.Close() if err != nil { - err = fmt.Errorf("Error getting officeHours by course from database: %w", err) + err = fmt.Errorf("error getting officeHours by course from database: %w", err) if !errors.Is(err, sql.ErrNoRows) { log.Println(err.Error()) } @@ -75,7 +75,7 @@ func (r *OfficeHourRepo) FindByRoom(room models.Room, activeOnly bool) ([]models rows, err = r.db.Query("SELECT * FROM officeHour WHERE room=?", room.Id) } if err != nil { - err = fmt.Errorf("Error getting officeHours by room from database: %w", err) + err = fmt.Errorf("error getting officeHours by room from database: %w", err) if !errors.Is(err, sql.ErrNoRows) { log.Println(err.Error()) } @@ -101,7 +101,7 @@ func (r *OfficeHourRepo) Add(officeHour models.OfficeHour) (int, error) { } officeHour.Tutor, err = r.tutorRepo.FindByNameAndEmail(officeHour.Tutor.Name, officeHour.Tutor.Email) if err != nil { - err = fmt.Errorf("Newly added tutor not found: %w", err) + err = fmt.Errorf("newly added tutor not found: %w", err) log.Println(err.Error()) return 0, err } @@ -140,7 +140,7 @@ func (r *OfficeHourRepo) Add(officeHour models.OfficeHour) (int, error) { } id, lastInsertIdErr := sqlResult.LastInsertId() if lastInsertIdErr != nil { - log.Printf("Error getting Id for new tutor: %s", lastInsertIdErr.Error()) + log.Printf("error getting Id for new tutor: %s", lastInsertIdErr.Error()) } return int(id), err } @@ -148,7 +148,7 @@ func (r *OfficeHourRepo) Add(officeHour models.OfficeHour) (int, error) { func (r *OfficeHourRepo) Delete(officeHour models.OfficeHour) error { _, err := r.db.Exec("DELETE FROM officeHour WHERE id=?", officeHour.Id) if err != nil { - err = fmt.Errorf("Error deleting officeHour from database: %w", err) + err = fmt.Errorf("error deleting officeHour from database: %w", err) log.Println(err.Error()) return err } @@ -160,26 +160,26 @@ func (r *OfficeHourRepo) getFromRow(row *sql.Row) (models.OfficeHour, error) { var week, day, hour, minute, tutorId, courseId, roomId int err := row.Scan(&officeHour.Id, &tutorId, &day, &hour, &minute, &roomId, &officeHour.RoomName, &courseId, &week, &officeHour.Info, &officeHour.Active, &officeHour.Duration) if err != nil { - err = fmt.Errorf("Error getting single officeHour row from database: %w", err) + err = fmt.Errorf("error getting single officeHour row from database: %w", err) log.Println(err.Error()) return models.OfficeHour{}, err } officeHour.Date = models.Date{Week: week, Day: day, Hour: hour, Minute: minute} officeHour.Room, err = r.roomRepo.FindById(roomId) if err != nil { - err = fmt.Errorf("Error finding room by id %d for office hour: %w", roomId, err) + err = fmt.Errorf("error finding room by id %d for office hour: %w", roomId, err) log.Println(err.Error()) return officeHour, err } officeHour.Tutor, err = r.tutorRepo.FindById(tutorId) if err != nil { - err = fmt.Errorf("Error finding tutor by id %d for office hour: %w", tutorId, err) + err = fmt.Errorf("error finding tutor by id %d for office hour: %w", tutorId, err) log.Println(err.Error()) return officeHour, err } officeHour.Course, err = r.courseRepo.FindById(courseId) if err != nil { - err = fmt.Errorf("Error finding course by id %d for office hour: %w", courseId, err) + err = fmt.Errorf("error finding course by id %d for office hour: %w", courseId, err) log.Println(err.Error()) return officeHour, err } @@ -193,24 +193,24 @@ func (r *OfficeHourRepo) getFromRows(rows *sql.Rows) ([]models.OfficeHour, error var week, day, hour, minute, tutorId, roomId, courseId int var err error if err := rows.Scan(&officeHour.Id, &tutorId, &day, &hour, &minute, &roomId, &officeHour.RoomName, &courseId, &week, &officeHour.Info, &officeHour.Active, &officeHour.Duration); err != nil { - return officeHours, fmt.Errorf("Error getting multiple officeHour rows from database: %w", err) + return officeHours, fmt.Errorf("error getting multiple officeHour rows from database: %w", err) } officeHour.Date = models.Date{Week: week, Day: day, Hour: hour, Minute: minute} officeHour.Room, err = r.roomRepo.FindById(roomId) if err != nil { - err = fmt.Errorf("Error finding room by id %d for office hour: %w", roomId, err) + err = fmt.Errorf("error finding room by id %d for office hour: %w", roomId, err) log.Println(err.Error()) return officeHours, err } officeHour.Tutor, err = r.tutorRepo.FindById(tutorId) if err != nil { - err = fmt.Errorf("Error finding tutor by id %d for office hour: %w", tutorId, err) + err = fmt.Errorf("error finding tutor by id %d for office hour: %w", tutorId, err) log.Println(err.Error()) return officeHours, err } officeHour.Course, err = r.courseRepo.FindById(courseId) if err != nil { - err = fmt.Errorf("Error finding course by id %d for office hour: %w", courseId, err) + err = fmt.Errorf("error finding course by id %d for office hour: %w", courseId, err) log.Println(err.Error()) return officeHours, err } @@ -229,7 +229,7 @@ func (r *OfficeHourRepo) NumberByTimeSpanAndRoom(date models.Date, duration int, rows, err = r.db.Query("SELECT * FROM officeHour WHERE room=?", room.Id) } if err != nil { - err = fmt.Errorf("Error getting officeHours by timespan and room from database: %w", err) + err = fmt.Errorf("error getting officeHours by timespan and room from database: %w", err) log.Println(err.Error()) return 0, err } diff --git a/repositories/request.go b/repositories/request.go index 8dec68a..47e418d 100644 --- a/repositories/request.go +++ b/repositories/request.go @@ -55,7 +55,7 @@ func (r *RequestRepo) FindByOfficeHour(officeHour models.OfficeHour) ([]models.R var request models.Request var officeHourId int if err := rows.Scan(&request.Id, &officeHourId, &request.Action, &request.Secret); err != nil { - err = fmt.Errorf("Error scanning request row: %w", err) + err = fmt.Errorf("error scanning request row: %w", err) log.Println(err.Error()) return requests, err } @@ -110,7 +110,7 @@ func (r *RequestRepo) Execute(request models.Request) error { r.db.Exec("DELETE FROM request WHERE officeHour=?", request.OfficeHour.Id) err = r.officeHourRepo.Delete(request.OfficeHour) default: - log.Printf("Executing request: Action type %d unknown.", request.Action) + log.Printf("executing request: Action type %d unknown.", request.Action) _, err = r.db.Exec("DELETE FROM request WHERE id=?", request.Id) } return err @@ -140,7 +140,7 @@ func (r *RequestRepo) sendConfirmationMail(request models.Request) error { }{r.config, request, template.HTML("<" + randomString(15) + "@" + r.config.Server.Domain + ">")} err := templating.WriteTemplate(&message, "confirmationMail", data) if err != nil { - err = fmt.Errorf("Error parsing confirmation Mail: %w", err) + err = fmt.Errorf("error parsing confirmation Mail: %w", err) log.Println(err.Error()) return err } @@ -156,7 +156,7 @@ func (r *RequestRepo) sendConfirmationMail(request models.Request) error { } err = smtp.SendMail(fmt.Sprintf("%s:%d", r.config.Mailer.SmtpHost, r.config.Mailer.SmtpPort), auth, string(r.config.Mailer.FromName), to, message.Bytes()) if err != nil { - err = fmt.Errorf("Error sending mail by smtp: %w", err) + err = fmt.Errorf("error sending mail by smtp: %w", err) log.Println(err.Error()) } return err diff --git a/repositories/room.go b/repositories/room.go index f86aabb..08576f3 100644 --- a/repositories/room.go +++ b/repositories/room.go @@ -31,7 +31,7 @@ func (r *RoomRepo) FindById(id int) (models.Room, error) { row := r.db.QueryRow("SELECT * FROM room WHERE id=?", id) var room models.Room if err := row.Scan(&room.Id, &room.Name, &room.MaxOccupy); err != nil { - err = fmt.Errorf("Error scanning row to get room: %w", err) + err = fmt.Errorf("error scanning row to get room: %w", err) if !errors.Is(err, sql.ErrNoRows) { log.Println(err.Error()) } @@ -43,7 +43,7 @@ func (r *RoomRepo) FindById(id int) (models.Room, error) { func (r *RoomRepo) GetAll() ([]models.Room, error) { rows, err := r.db.Query("SELECT * FROM room ORDER BY name ASC") if err != nil { - err = fmt.Errorf("Error getting all rooms: %w", err) + err = fmt.Errorf("error getting all rooms: %w", err) log.Println(err.Error()) return nil, err } @@ -53,7 +53,7 @@ func (r *RoomRepo) GetAll() ([]models.Room, error) { for rows.Next() { var room models.Room if err := rows.Scan(&room.Id, &room.Name, &room.MaxOccupy); err != nil { - err = fmt.Errorf("Error scanning row to get room: %w", err) + err = fmt.Errorf("error scanning row to get room: %w", err) return rooms, err } rooms = append(rooms, room) diff --git a/repositories/tutor.go b/repositories/tutor.go index 6523861..6dc3f1d 100644 --- a/repositories/tutor.go +++ b/repositories/tutor.go @@ -58,7 +58,7 @@ func (r *TutorRepo) Add(tutor models.Tutor) (int, error) { } id, lastInsertIdErr := sqlResult.LastInsertId() if lastInsertIdErr != nil { - log.Printf("Error getting Id for new tutor: %s", lastInsertIdErr.Error()) + log.Printf("error getting Id for new tutor: %s", lastInsertIdErr.Error()) } return int(id), err } @@ -80,7 +80,7 @@ func (r *TutorRepo) getFromRows(rows *sql.Rows) ([]models.Tutor, error) { for rows.Next() { var tutor models.Tutor if err := rows.Scan(&tutor.Id, &tutor.Name, &tutor.Email, &tutor.SubscribeToMailinglist); err != nil { - err = fmt.Errorf("Error scanning tutor row: %w", err) + err = fmt.Errorf("error scanning tutor row: %w", err) log.Println(err.Error()) return tutors, err } diff --git a/sqldb/sqldb.go b/sqldb/sqldb.go index 5460662..d77c9ba 100644 --- a/sqldb/sqldb.go +++ b/sqldb/sqldb.go @@ -21,7 +21,7 @@ func Connect(config config.Config) (*sql.DB, error) { config.SQL.MysqlPort, config.SQL.MysqlDatabase) default: - return nil, fmt.Errorf("Type of database not recognised: %s", config.SQL.Type) + return nil, fmt.Errorf("type of database not recognised: %s", config.SQL.Type) } } @@ -29,7 +29,7 @@ func Connect(config config.Config) (*sql.DB, error) { func connectSQLite(file string) (*sql.DB, error) { db, err := sql.Open("sqlite3", file) if err != nil { - return db, fmt.Errorf("Error opening SQLite database: %w", err) + return db, fmt.Errorf("error opening SQLite database: %w", err) } return db, nil } @@ -38,12 +38,12 @@ func connectSQLite(file string) (*sql.DB, error) { func connectMysql(user string, password string, address string, port int, database string) (*sql.DB, error) { db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", user, password, address, port, database)) if err != nil { - return db, fmt.Errorf("Error connecting to Mysql database: %w", err) + return db, fmt.Errorf("error connecting to Mysql database: %w", err) } err = db.Ping() if err != nil { - return db, fmt.Errorf("Error pinging Mysql database: %w", err) + return db, fmt.Errorf("error pinging Mysql database: %w", err) } return db, nil }