diff --git a/cmd/boardvoting/config.go b/cmd/boardvoting/config.go index 023034f..203dbb6 100644 --- a/cmd/boardvoting/config.go +++ b/cmd/boardvoting/config.go @@ -30,6 +30,7 @@ const ( httpReadHeaderTimeout = 5 * time.Second httpReadTimeout = 5 * time.Second httpWriteTimeout = 10 * time.Second + smtpPort = 25 smtpTimeout = 10 * time.Second ) @@ -80,7 +81,7 @@ func parseConfig(configFile string) (*Config, error) { }, MailConfig: &mailConfig{ SMTPHost: "localhost", - SMTPPort: 25, + SMTPPort: smtpPort, SMTPTimeOut: smtpTimeout, }, } diff --git a/cmd/boardvoting/handlers.go b/cmd/boardvoting/handlers.go index 1dc0dc2..3886aca 100644 --- a/cmd/boardvoting/handlers.go +++ b/cmd/boardvoting/handlers.go @@ -659,8 +659,10 @@ func (app *application) healthCheck(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Refresh", "10") w.Header().Add("Cache-Control", "no-store") - var err error - var hasErrors = false + var ( + err error + hasErrors = false + ) if err = app.mailNotifier.Ping(); err != nil { hasErrors = true diff --git a/cmd/boardvoting/handlers_test.go b/cmd/boardvoting/handlers_test.go index a00b67a..d60cdb1 100644 --- a/cmd/boardvoting/handlers_test.go +++ b/cmd/boardvoting/handlers_test.go @@ -48,8 +48,9 @@ func prepareTestDb(t *testing.T) *sqlx.DB { return dbx } -func StartTestTcpServer(t *testing.T) int { +func StartTestTCPServer(t *testing.T) int { t.Helper() + port, err := tcputil.EmptyPort() require.NoError(t, err) @@ -68,6 +69,7 @@ func StartTestTcpServer(t *testing.T) int { if err != nil { t.Errorf("could not accept connection: %v", err) + return } @@ -81,7 +83,7 @@ func StartTestTcpServer(t *testing.T) int { } func TestApplication_healthCheck(t *testing.T) { - port := StartTestTcpServer(t) + port := StartTestTCPServer(t) t.Run("check with valid DB", func(t *testing.T) { rr := httptest.NewRecorder() diff --git a/cmd/boardvoting/jobs.go b/cmd/boardvoting/jobs.go index dd40476..f3c0b08 100644 --- a/cmd/boardvoting/jobs.go +++ b/cmd/boardvoting/jobs.go @@ -40,7 +40,8 @@ type RemindVotersJob struct { } func (r *RemindVotersJob) Schedule() { - // TODO: check logic. It would make more sense to remind at a specific interval before the next pending decision is closed + // TODO: check logic. It would make more sense to remind at a specific interval before the next pending + // decision is closed const reminderDays = 3 year, month, day := time.Now().UTC().Date() @@ -235,8 +236,8 @@ func (js *JobScheduler) Schedule() { for { select { - case jobId := <-js.rescheduleChannel: - js.jobs[jobId].Schedule() + case jobID := <-js.rescheduleChannel: + js.jobs[jobID].Schedule() case <-js.quitChannel: for _, job := range js.jobs { job.Stop() diff --git a/cmd/boardvoting/middleware.go b/cmd/boardvoting/middleware.go index 9a51834..b4fdf92 100644 --- a/cmd/boardvoting/middleware.go +++ b/cmd/boardvoting/middleware.go @@ -70,6 +70,7 @@ func (app *application) authenticateRequest(r *http.Request) (*models.User, *x50 clientCert := r.TLS.PeerCertificates[0] allowClientAuth := false + for _, eku := range clientCert.ExtKeyUsage { if eku == x509.ExtKeyUsageClientAuth { allowClientAuth = true diff --git a/internal/validator/validator.go b/internal/validator/validator.go index c5f5780..07f8b32 100644 --- a/internal/validator/validator.go +++ b/internal/validator/validator.go @@ -53,6 +53,7 @@ func NotBlank(value string) bool { func NotNil(value any) bool { val := reflect.ValueOf(value) + return !val.IsNil() }