Self-hosted email delivery platform that enables applications to send emails via HTTP APIs while handling SMTP delivery, templates, storage, security, and analytics. Fully self-hostable alternative to services like SendGrid or Mailgun.
Go email-relayemail-routinghttp-to-smtpmail-deliverymailchimp-alternativemailgun-alternativemailsendermailservermailtemplatemailtestpostmark-alternativesend-emailsendgrid-alternativesendmailtransactional-emailtransactional-outbox
fix: resolve lint issues across codebase (golangci-lint clean)
Jonas Kanindac68d7fd4474c
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.ymlnew file mode 100644index 0000000..a7fc8e4--- /dev/null+++ b/.github/workflows/lint.yml@@ -0,0 +1,23 @@+name: Lint++on:+ push:+ pull_request:++jobs:+ lint:+ name: Run on Ubuntu+ runs-on: ubuntu-latest+ steps:+ - name: Clone the code+ uses: actions/checkout@v4++ - name: Setup Go+ uses: actions/setup-go@v5+ with:+ go-version: '~1.26'++ - name: Run linter+ uses: golangci/golangci-lint-action@v7+ with:+ version: v2.9.0\ No newline at end of filediff --git a/internal/routes/oauth_routes.go b/internal/routes/oauth_routes.goindex 09cc442..d564928 100644--- a/internal/routes/oauth_routes.go+++ b/internal/routes/oauth_routes.go@@ -13,7 +13,8 @@ func (r *Router) oauthRoutes() []okapi.RouteDefinition {// Public OAuth routes (no auth required)oauthPublic := r.v1.Group("/auth/oauth").WithTags([]string{"OAuth"})- routes := []okapi.RouteDefinition{+ routes := make([]okapi.RouteDefinition, 0, 12)+ routes = append(routes, []okapi.RouteDefinition{{Method: http.MethodGet,Path: "/providers",@@ -46,7 +47,7 @@ func (r *Router) oauthRoutes() []okapi.RouteDefinition {okapi.DocHide(),},},- }+ }...)// Authenticated OAuth routes (linked accounts)oauthUser := r.v1.Group("/users/me/oauth", r.mw.jwtAuth.Middleware).WithTags([]string{"OAuth"})diff --git a/internal/routes/workspace_routes.go b/internal/routes/workspace_routes.goindex eb0fd60..75a01bc 100644--- a/internal/routes/workspace_routes.go+++ b/internal/routes/workspace_routes.go@@ -32,7 +32,8 @@ func (r *Router) workspaceRoutes() []okapi.RouteDefinition {userGroup := r.v1.Group("/workspaces", r.mw.jwtAuth.Middleware).WithTags([]string{"Workspaces"})userGroup.WithBearerAuth()- routes := []okapi.RouteDefinition{+ routes := make([]okapi.RouteDefinition, 0, 20)+ routes = append(routes, []okapi.RouteDefinition{{Method: http.MethodPost,Path: "",@@ -55,7 +56,7 @@ func (r *Router) workspaceRoutes() []okapi.RouteDefinition {Description: "List all workspaces the current user is a member of",Response: &dto.Response[[]handlers.WorkspaceResponse]{},},- }+ }...)// Workspace-scoped routes (require workspace context via middleware)wsGroup := r.v1.Group("/workspaces/current", r.mw.jwtAuth.Middleware, r.mw.workspace).WithTags([]string{"Workspaces"})diff --git a/internal/services/auth/oauth.go b/internal/services/auth/oauth.goindex 549dd92..3dac106 100644--- a/internal/services/auth/oauth.go+++ b/internal/services/auth/oauth.go@@ -186,7 +186,7 @@ func (s *OAuthService) fetchUserInfo(ctx context.Context, provider *models.OAuthif err != nil {return nil, err}- defer resp.Body.Close()+ defer func() { _ = resp.Body.Close() }()if resp.StatusCode != http.StatusOK {body, _ := io.ReadAll(resp.Body)diff --git a/internal/services/email/service.go b/internal/services/email/service.goindex 80510ea..36f069f 100644--- a/internal/services/email/service.go+++ b/internal/services/email/service.go@@ -187,7 +187,7 @@ func (s *Service) DownloadAttachments(ctx context.Context, attachments []models.return nil, fmt.Errorf("failed to download attachment %q: %w", att.Filename, err)}data, err := io.ReadAll(rc)- rc.Close()+ _ = rc.Close()if err != nil {return nil, fmt.Errorf("failed to read attachment %q: %w", att.Filename, err)}diff --git a/internal/services/tracking/tracking.go b/internal/services/tracking/tracking.goindex a44385e..a8a833b 100644--- a/internal/services/tracking/tracking.go+++ b/internal/services/tracking/tracking.go@@ -128,6 +128,6 @@ func (s *Service) UnsubscribeURL(messageID uint) string {// hashLink generates a deterministic hash for a campaign + URL combination.func hashLink(campaignID uint, url string) string {h := sha256.New()- h.Write([]byte(fmt.Sprintf("%d:%s", campaignID, url)))+ _, _ = fmt.Fprintf(h, "%d:%s", campaignID, url)return hex.EncodeToString(h.Sum(nil))[:16]}diff --git a/internal/storage/blob/fs.go b/internal/storage/blob/fs.goindex 640d2e4..856b108 100644--- a/internal/storage/blob/fs.go+++ b/internal/storage/blob/fs.go@@ -49,7 +49,7 @@ func (f *fsStore) Put(_ context.Context, key string, r io.Reader, _ string) erroif err != nil {return fmt.Errorf("fs create %q: %w", path, err)}- defer file.Close()+ defer func() { _ = file.Close() }()if _, err := io.Copy(file, r); err != nil {return fmt.Errorf("fs write %q: %w", path, err)}diff --git a/internal/storage/repositories/subscriber_repo.go b/internal/storage/repositories/subscriber_repo.goindex 34f1ed3..3cd2d66 100644--- a/internal/storage/repositories/subscriber_repo.go+++ b/internal/storage/repositories/subscriber_repo.go@@ -222,7 +222,7 @@ func (r *SubscriberRepository) applyFilterRules(q *gorm.DB, rules models.FilterR// isAlphanumericUnderscore returns true if s contains only [a-zA-Z0-9_-].func isAlphanumericUnderscore(s string) bool {for _, c := range s {- if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_' || c == '-') {+ if (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && (c < '0' || c > '9') && c != '_' && c != '-' {return false}}diff --git a/internal/worker/campaign_processor.go b/internal/worker/campaign_processor.goindex 9e722af..30f1521 100644--- a/internal/worker/campaign_processor.go+++ b/internal/worker/campaign_processor.go@@ -109,13 +109,13 @@ func (p *CampaignProcessor) HandleCampaignStart(_ context.Context, t *asynq.Taskscope := repositories.ResourceScope{UserID: campaign.UserID, WorkspaceID: campaign.WorkspaceID}if list.Type == models.SubscriberListTypeDynamic {- // Dynamic list: resolve via filter rules (-1 means no limit in GORM)+ // Dynamic list: resolve via filter rulessubscribers, _, err = p.subscriberRepo.FindByFilterRules(scope, list.FilterRules, -1, 0)if err != nil {return fmt.Errorf("failed to resolve dynamic list: %w", err)}} else {- // Static list: get all members (-1 means no limit in GORM)+ // Static list: get all memberssubscribers, _, err = p.listRepo.ListMembers(list.ID, -1, 0)if err != nil {return fmt.Errorf("failed to list members: %w", err)diff --git a/internal/worker/handler.go b/internal/worker/handler.goindex d424a62..e92c581 100644--- a/internal/worker/handler.go+++ b/internal/worker/handler.go@@ -130,7 +130,7 @@ func (h *EmailSendHandler) ProcessTask(ctx context.Context, t *asynq.Task) error}}if !allowed {- h.markFailed(em, fmt.Sprintf("sender %q is not in the allowed emails list", em.Sender), 0)+ h.markFailed(em, fmt.Sprintf("sender %q is not in the allowed emails list", em.Sender))return nil}}@@ -145,7 +145,7 @@ func (h *EmailSendHandler) ProcessTask(ctx context.Context, t *asynq.Task) error// In strict mode the sender's domain must be ownership-verified.if shared.SecurityMode == models.ServerSecurityModeStrict {if h.domainRepo == nil || !h.domainRepo.IsOwnershipVerified(em.UserID, domain) {- h.markFailed(em, fmt.Sprintf("shared server %q requires verified domain ownership for %q", shared.Name, domain), 0)+ h.markFailed(em, fmt.Sprintf("shared server %q requires verified domain ownership for %q", shared.Name, domain))return nil}}@@ -157,7 +157,7 @@ func (h *EmailSendHandler) ProcessTask(ctx context.Context, t *asynq.Task) error}if smtpServer == nil {- h.markFailed(em, "no SMTP server configured for this account or domain", 0)+ h.markFailed(em, "no SMTP server configured for this account or domain")// Don't retry – adding a server won't happen automatically.return nil}@@ -179,13 +179,13 @@ func (h *EmailSendHandler) ProcessTask(ctx context.Context, t *asynq.Task) errorif att.StorageKey != "" && att.Content == "" {rc, err := h.blobStore.Get(ctx, att.StorageKey)if err != nil {- h.markFailed(em, fmt.Sprintf("failed to fetch attachment %q from storage: %v", att.Filename, err), 0)+ h.markFailed(em, fmt.Sprintf("failed to fetch attachment %q from storage: %v", att.Filename, err))return nil}data, err := io.ReadAll(rc)- rc.Close()+ _ = rc.Close()if err != nil {- h.markFailed(em, fmt.Sprintf("failed to read attachment %q: %v", att.Filename, err), 0)+ h.markFailed(em, fmt.Sprintf("failed to read attachment %q: %v", att.Filename, err))return nil}attachments[i].Content = base64.StdEncoding.EncodeToString(data)@@ -241,13 +241,10 @@ func (h *EmailSendHandler) ProcessTask(ctx context.Context, t *asynq.Task) errorreturn nil}-func (h *EmailSendHandler) markFailed(em *models.Email, reason string, sharedServerID uint) {+func (h *EmailSendHandler) markFailed(em *models.Email, reason string) {em.Status = models.EmailStatusFailedem.ErrorMessage = reason_ = h.emailRepo.Update(em)- if sharedServerID != 0 && h.serverRepo != nil {- go h.serverRepo.IncrementFailedCount(sharedServerID)- }h.dispatcher.Dispatch(em.UserID, "email.failed", em.UUID, em.Sender)if h.onFailed != nil {h.onFailed()