Skip to content

armgit / posta

Public Imported from GitHub
0

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.

chore: fix all golangci-lint findings

Jonas Kaninda09540bca5927
diff --git a/.golangci.yml b/.golangci.yml
index 4cbc498..fffe069 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -22,6 +22,12 @@ linters:
- unparam
- unused
settings:
+ goconst:
+ # A JSON field name or a database column used as a map key is data, not a
+ # magic constant: hoisting `okapi.M{"message": ...}` behind an identifier
+ # makes the response shape harder to read, not easier. Without this, the
+ # single string "message" is reported 43 times across the handlers.
+ ignore-map-keys: true
gocyclo:
min-complexity: 75
revive:
diff --git a/internal/config/security.go b/internal/config/security.go
index c61abdc..aefb8f9 100644
--- a/internal/config/security.go
+++ b/internal/config/security.go
@@ -64,15 +64,18 @@ type secretProblem struct {
fatal bool
}
+// envJWTSecret names the setting these checks report on.
+const envJWTSecret = "POSTA_JWT_SECRET"
+
func (c *Config) jwtSecretProblem() *secretProblem {
switch {
case strings.TrimSpace(c.JWTSecret) == "":
- return &secretProblem{"POSTA_JWT_SECRET", "is empty", true}
+ return &secretProblem{envJWTSecret, "is empty", true}
case isPlaceholder(c.JWTSecret):
- return &secretProblem{"POSTA_JWT_SECRET", "is the published placeholder value, so sessions can be forged by anyone", true}
+ return &secretProblem{envJWTSecret, "is the published placeholder value, so sessions can be forged by anyone", true}
case len(c.JWTSecret) < MinJWTSecretLength:
return &secretProblem{
- "POSTA_JWT_SECRET",
+ envJWTSecret,
fmt.Sprintf("is shorter than the recommended %d characters and may be brute-forced offline from a captured token", MinJWTSecretLength),
false,
}
diff --git a/internal/handlers/helper.go b/internal/handlers/helper.go
index 4791c1e..7d632ec 100644
--- a/internal/handlers/helper.go
+++ b/internal/handlers/helper.go
@@ -16,6 +16,11 @@ import (
"gorm.io/gorm"
)
+// planSourceGlobalSettings is returned in place of a plan when a workspace has
+// none assigned and the platform-wide settings apply. The dashboard branches on
+// this exact value.
+const planSourceGlobalSettings = "global_settings"
+
var errForbidden = errors.New("insufficient workspace permissions: editor role or higher required")
// 1x1 transparent GIF
diff --git a/internal/handlers/plan_handler.go b/internal/handlers/plan_handler.go
index 5808700..ce90e5f 100644
--- a/internal/handlers/plan_handler.go
+++ b/internal/handlers/plan_handler.go
@@ -336,7 +336,7 @@ func (h *PlanHandler) GetWorkspacePlan(c *okapi.Context, req *WorkspacePlanReque
plan := h.planService.EffectivePlan(&wsID)
if plan == nil {
- return ok(c, okapi.M{"plan": nil, "source": "global_settings"})
+ return ok(c, okapi.M{"plan": nil, "source": planSourceGlobalSettings})
}
return ok(c, plan)
@@ -392,7 +392,7 @@ func (h *PlanHandler) GetUserPlan(c *okapi.Context, req *UserPlanRequest) error
plan := h.planService.EffectiveUserPlan(user.ID)
if plan == nil {
- return ok(c, okapi.M{"plan": nil, "source": "global_settings"})
+ return ok(c, okapi.M{"plan": nil, "source": planSourceGlobalSettings})
}
return ok(c, plan)
@@ -404,7 +404,7 @@ func (h *PlanHandler) GetMyPlan(c *okapi.Context) error {
plan := h.planService.EffectiveUserPlan(userID)
if plan == nil {
- return ok(c, okapi.M{"plan": nil, "source": "global_settings"})
+ return ok(c, okapi.M{"plan": nil, "source": planSourceGlobalSettings})
}
return ok(c, plan)
diff --git a/internal/handlers/workspace_handler.go b/internal/handlers/workspace_handler.go
index 8e25ae5..3e0eeee 100644
--- a/internal/handlers/workspace_handler.go
+++ b/internal/handlers/workspace_handler.go
@@ -788,11 +788,11 @@ func (h *WorkspaceHandler) logAudit(c *okapi.Context, workspaceID uint, action,
func (h *WorkspaceHandler) GetPlan(c *okapi.Context) error {
wsID := uint(c.GetInt("workspace_id"))
if h.planService == nil {
- return ok(c, okapi.M{"plan": nil, "source": "global_settings"})
+ return ok(c, okapi.M{"plan": nil, "source": planSourceGlobalSettings})
}
plan := h.planService.EffectivePlan(&wsID)
if plan == nil {
- return ok(c, okapi.M{"plan": nil, "source": "global_settings"})
+ return ok(c, okapi.M{"plan": nil, "source": planSourceGlobalSettings})
}
return ok(c, plan)
}
diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go
index cf2315c..0f573db 100644
--- a/internal/metrics/metrics.go
+++ b/internal/metrics/metrics.go
@@ -13,13 +13,17 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
)
+// labelStatus is the Prometheus label shared by the request, email, and
+// message counters.
+const labelStatus = "status"
+
var (
httpRequestsTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "posta_http_requests_total",
Help: "Total number of HTTP requests",
},
- []string{"method", "path", "status"},
+ []string{"method", "path", labelStatus},
)
httpRequestDuration = prometheus.NewHistogramVec(
@@ -64,7 +68,7 @@ var (
Name: "posta_webhook_deliveries_total",
Help: "Total number of webhook delivery attempts by status",
},
- []string{"status"},
+ []string{labelStatus},
)
webhookDeliveryDuration = prometheus.NewHistogram(
@@ -103,7 +107,7 @@ var (
Name: "posta_form_messages_received_total",
Help: "Total number of web form messages stored, by scan status",
},
- []string{"status"},
+ []string{labelStatus},
)
messageNotificationsTotal = prometheus.NewCounter(
diff --git a/internal/middlewares/default_workspace_test.go b/internal/middlewares/default_workspace_test.go
index 5bb81e1..ace6659 100644
--- a/internal/middlewares/default_workspace_test.go
+++ b/internal/middlewares/default_workspace_test.go
@@ -98,7 +98,7 @@ func TestDefaultWorkspaceFallbackSkippedForBoundAPIKey(t *testing.T) {
app.Get("/t", func(c *okapi.Context) error {
gotWorkspace = c.GetInt(CtxWorkspaceID)
return c.JSON(http.StatusOK, okapi.M{"ok": true})
- }).Use(stashAPIKey(1, 7, models.ScopeAll), OptionalWorkspaceMiddleware(nil, resolver))
+ }).Use(stashAPIKey(7, models.ScopeAll), OptionalWorkspaceMiddleware(nil, resolver))
rec := httptest.NewRecorder()
app.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/t", nil))
diff --git a/internal/middlewares/workspace_test.go b/internal/middlewares/workspace_test.go
index 47afefe..9316020 100644
--- a/internal/middlewares/workspace_test.go
+++ b/internal/middlewares/workspace_test.go
@@ -14,10 +14,14 @@ import (
)
// stashAPIKey mimics authenticateAPIKey's context for a workspace-bound key.
-// boundWorkspace of 0 means an account-wide key.
-func stashAPIKey(userID, boundWorkspace int, scopes string) okapi.Middleware {
+// boundWorkspace of 0 means an account-wide key. The caller's identity is
+// irrelevant to what these tests assert — workspace binding and scopes — so it
+// is fixed rather than threaded through every call.
+const stubAPIKeyUserID = 1
+
+func stashAPIKey(boundWorkspace int, scopes string) okapi.Middleware {
return func(c *okapi.Context) error {
- c.Set(CtxUserID, userID)
+ c.Set(CtxUserID, stubAPIKeyUserID)
c.Set(CtxAuthMethod, AuthMethodAPIKey)
c.Set(CtxAPIKeyScopes, scopes)
if boundWorkspace > 0 {
@@ -81,7 +85,7 @@ func TestRequireWorkspace_BoundAPIKey(t *testing.T) {
"workspace_id": c.GetInt(CtxWorkspaceID),
"role": c.GetString(CtxWorkspaceRole),
})
- }).Use(stashAPIKey(1, 7, models.ScopeRead), RequireWorkspaceMiddleware(nil, nil))
+ }).Use(stashAPIKey(7, models.ScopeRead), RequireWorkspaceMiddleware(nil, nil))
req := httptest.NewRequest(http.MethodGet, "/ws", nil)
if tc.header != "" {
@@ -166,7 +170,7 @@ func TestWorkspaceScopeEnforcement(t *testing.T) {
o := okapi.NewTestServer(t)
route(o, tc.method, "/api/v1/workspaces/current"+tc.path, func(c *okapi.Context) error {
return c.String(http.StatusOK, "ok")
- }).Use(stashAPIKey(1, 7, tc.scopes), RequireWorkspaceMiddleware(nil, nil))
+ }).Use(stashAPIKey(7, tc.scopes), RequireWorkspaceMiddleware(nil, nil))
req := httptest.NewRequest(tc.method, "/api/v1/workspaces/current"+tc.path, nil)
rec := httptest.NewRecorder()
@@ -231,7 +235,7 @@ func TestWorkspaceFromQuery_BoundKeyIgnoresMismatchedQuery(t *testing.T) {
o := okapi.NewTestServer(t)
o.Get("/stream", func(c *okapi.Context) error {
return c.String(http.StatusOK, "ok")
- }).Use(stashAPIKey(1, 7, models.ScopeRead), WorkspaceFromQueryOrHeader(nil, nil))
+ }).Use(stashAPIKey(7, models.ScopeRead), WorkspaceFromQueryOrHeader(nil, nil))
rec := httptest.NewRecorder()
o.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/stream?workspace_id=9", nil))
@@ -240,3 +244,24 @@ func TestWorkspaceFromQuery_BoundKeyIgnoresMismatchedQuery(t *testing.T) {
t.Errorf("status = %d, want 403", rec.Code)
}
}
+
+// An account-wide API key carries no workspace binding, so it has nothing to
+// fall back on: a route that demands a workspace must refuse it rather than
+// resolving one on its behalf. This exercises stashAPIKey's boundWorkspace == 0
+// branch, which every other case skips.
+func TestRequireWorkspace_AccountWideKeyWithoutHeader(t *testing.T) {
+ o := okapi.New()
+ o.Get("/ws", func(c *okapi.Context) error {
+ return c.JSON(http.StatusOK, okapi.M{"workspace": c.GetInt(CtxWorkspaceID)})
+ }).Use(stashAPIKey(0, models.ScopeAll), RequireWorkspaceMiddleware(nil, nil))
+
+ rec := httptest.NewRecorder()
+ o.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/ws", nil))
+
+ if rec.Code != http.StatusBadRequest {
+ t.Fatalf("status = %d, want 400", rec.Code)
+ }
+ if !strings.Contains(rec.Body.String(), WorkspaceHeader) {
+ t.Fatalf("response should name the missing header, got %s", rec.Body.String())
+ }
+}
diff --git a/internal/models/setting.go b/internal/models/setting.go
index 4408ef4..6fe2d52 100644
--- a/internal/models/setting.go
+++ b/internal/models/setting.go
@@ -5,6 +5,21 @@ package models
import "time"
+// Setting value types. The frontend renders a control from this hint, so the
+// vocabulary is closed: a typo produces a text box where a checkbox belongs.
+const (
+ SettingTypeString = "string"
+ SettingTypeBool = "bool"
+ SettingTypeInt = "int"
+)
+
+// Serialized values for a SettingTypeBool entry. Values are stored as text, so
+// these are the only two a bool setting may hold.
+const (
+ SettingTrue = "true"
+ SettingFalse = "false"
+)
+
// Setting represents a platform-wide configuration entry managed by admins.
// Settings are stored as key-value pairs with a type hint for the frontend.
type Setting struct {
diff --git a/internal/routes/admin_routes.go b/internal/routes/admin_routes.go
index 13dedfb..82bcd39 100644
--- a/internal/routes/admin_routes.go
+++ b/internal/routes/admin_routes.go
@@ -16,8 +16,8 @@ import (
// adminRoutes returns route definitions for admin endpoints.
func (r *Router) adminRoutes() []okapi.RouteDefinition {
adminGroup := r.v1.Group("/admin", r.mw.jwtAdminAuth.Middleware).WithTagInfo(okapi.GroupTag{
- Name: "Admin",
- Description: "Platform-level administration: users, workspaces, global settings, OAuth providers, and live event streams. Admin-only.",
+ Name: tagAdmin,
+ Description: descAdmin,
})
adminGroup.WithBearerAuth()
@@ -78,7 +78,7 @@ func (r *Router) adminRoutes() []okapi.RouteDefinition {
Path: "/users/{id:int}",
Handler: okapi.H(r.h.admin.DeleteUser),
Group: adminGroup,
- Tags: []string{"Admin"},
+ Tags: []string{tagAdmin},
Summary: "Delete user",
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "User ID"),
@@ -91,7 +91,7 @@ func (r *Router) adminRoutes() []okapi.RouteDefinition {
Path: "/users/{id:int}/force",
Handler: okapi.H(r.h.admin.ForceDeleteUser),
Group: adminGroup,
- Tags: []string{"Admin"},
+ Tags: []string{tagAdmin},
Summary: "Force delete user",
Description: "Permanently delete a disabled user and all their data. The user must be disabled before force deletion.",
Options: []okapi.RouteOption{
@@ -249,7 +249,7 @@ func (r *Router) adminRoutes() []okapi.RouteDefinition {
// ==================== Platform Settings ====================
{
Method: http.MethodGet,
- Path: "/settings",
+ Path: pathSettings,
Handler: r.h.setting.GetSettings,
Group: adminGroup,
Summary: "Get platform settings",
@@ -257,7 +257,7 @@ func (r *Router) adminRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodPut,
- Path: "/settings",
+ Path: pathSettings,
Handler: okapi.H(r.h.setting.UpdateSettings),
Group: adminGroup,
Summary: "Update platform settings",
@@ -311,7 +311,7 @@ func (r *Router) adminRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodGet,
- Path: "/plans/{id:int}",
+ Path: pathPlanByID,
Handler: okapi.H(r.h.plan.Get),
Group: adminGroup,
Summary: "Get plan",
@@ -323,7 +323,7 @@ func (r *Router) adminRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodPut,
- Path: "/plans/{id:int}",
+ Path: pathPlanByID,
Handler: okapi.H(r.h.plan.Update),
Group: adminGroup,
Summary: "Update plan",
@@ -337,7 +337,7 @@ func (r *Router) adminRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodDelete,
- Path: "/plans/{id:int}",
+ Path: pathPlanByID,
Handler: okapi.H(r.h.plan.Delete),
Group: adminGroup,
Summary: "Delete plan",
@@ -415,7 +415,7 @@ func (r *Router) adminRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodGet,
- Path: "/servers/{id:int}",
+ Path: pathServerByID,
Handler: okapi.H(r.h.server.Get),
Group: adminGroup,
Summary: "Get shared SMTP server",
@@ -427,7 +427,7 @@ func (r *Router) adminRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodPut,
- Path: "/servers/{id:int}",
+ Path: pathServerByID,
Handler: okapi.H(r.h.server.Update),
Group: adminGroup,
Summary: "Update shared SMTP server",
@@ -440,10 +440,10 @@ func (r *Router) adminRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodDelete,
- Path: "/servers/{id:int}",
+ Path: pathServerByID,
Handler: okapi.H(r.h.server.Delete),
Group: adminGroup,
- Tags: []string{"Admin"},
+ Tags: []string{tagAdmin},
Summary: "Delete shared SMTP server",
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Server ID"),
@@ -508,8 +508,8 @@ func (r *Router) adminRoutes() []okapi.RouteDefinition {
// adminSSERoutes returns route definitions for admin SSE (Server-Sent Events) endpoints.
func (r *Router) adminSSERoutes() []okapi.RouteDefinition {
adminSSE := r.v1.Group("/admin", r.mw.jwtAdminAuth.Middleware).WithTagInfo(okapi.GroupTag{
- Name: "Admin",
- Description: "Platform-level administration: users, workspaces, global settings, OAuth providers, and live event streams. Admin-only.",
+ Name: tagAdmin,
+ Description: descAdmin,
})
return []okapi.RouteDefinition{
diff --git a/internal/routes/auth_routes.go b/internal/routes/auth_routes.go
index 474bdc0..7d6b8c4 100644
--- a/internal/routes/auth_routes.go
+++ b/internal/routes/auth_routes.go
@@ -347,7 +347,7 @@ func (r *Router) apiAuthRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodGet,
- Path: "/bounces",
+ Path: pathBounces,
Handler: okapi.H(r.h.bounce.List),
Group: apiRead,
Summary: "List bounces",
@@ -377,7 +377,7 @@ func (r *Router) apiAuthRoutes() []okapi.RouteDefinition {
// webhooks scope
{
Method: http.MethodGet,
- Path: "/webhooks",
+ Path: pathWebhooks,
Handler: okapi.H(r.h.webhook.List),
Group: apiWebhooks,
Summary: "List webhooks",
@@ -391,7 +391,7 @@ func (r *Router) apiAuthRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodPost,
- Path: "/webhooks",
+ Path: pathWebhooks,
Handler: okapi.H(r.h.webhook.Create),
Group: apiWebhooks,
Summary: "Create webhook",
diff --git a/internal/routes/inbound_routes.go b/internal/routes/inbound_routes.go
index 18ac980..798a75d 100644
--- a/internal/routes/inbound_routes.go
+++ b/internal/routes/inbound_routes.go
@@ -15,7 +15,7 @@ import (
// Protected by opaque secret/token — no JWT.
func (r *Router) inboundWebhookRoutes() []okapi.RouteDefinition {
inboundGroup := r.app.Group("/api/v1/inbound").WithTagInfo(okapi.GroupTag{
- Name: "Inbound",
+ Name: tagInbound,
Description: "Inbound email ingestion and retrieval: receive messages from upstream providers, browse history, and stream live events.",
})
return []okapi.RouteDefinition{
@@ -44,7 +44,7 @@ func (r *Router) inboundWorkspaceRoutes() []okapi.RouteDefinition {
// header, but it does send the session cookie, which r.mw.auth reads. Machine
// clients may stream with an API key via `?token=psk_…`.
userGroup := r.v1.Group("/workspaces/current", r.mw.auth, r.mw.workspaceQuery).WithTagInfo(okapi.GroupTag{
- Name: "Inbound",
+ Name: tagInbound,
Description: "Inbound email ingestion and retrieval: receive messages from upstream providers, browse history, and stream live events. Public ingest endpoints use opaque secrets; user endpoints use a dashboard session or an API key.",
})
userGroup.WithBearerAuth()
diff --git a/internal/routes/message_routes.go b/internal/routes/message_routes.go
index a226fcc..9de8b62 100644
--- a/internal/routes/message_routes.go
+++ b/internal/routes/message_routes.go
@@ -15,7 +15,7 @@ import (
func (r *Router) formIngestRoutes() []okapi.RouteDefinition {
ingestGroup := r.app.Group("/api/v1/f").WithTagInfo(okapi.GroupTag{
- Name: "Forms",
+ Name: tagForms,
Description: "Public form ingest. A website form posts here with the form's public key; no authentication is used, and access is governed by the form's origin allowlist, honeypot, nonce, and rate limits.",
})
@@ -50,13 +50,13 @@ func (r *Router) formIngestRoutes() []okapi.RouteDefinition {
func (r *Router) messageWorkspaceRoutes() []okapi.RouteDefinition {
opsGroup := r.v1.Group("/workspaces/current", r.mw.auth, r.mw.workspace).WithTagInfo(okapi.GroupTag{
- Name: "Messages",
+ Name: tagMessages,
Description: "Web form definitions, received messages, operator replies, and spam filters for the active workspace. Authenticated with a dashboard session or an API key bound to the workspace.",
})
opsGroup.WithBearerAuth()
streamGroup := r.v1.Group("/workspaces/current", r.mw.auth, r.mw.workspaceQuery).WithTagInfo(okapi.GroupTag{
- Name: "Messages",
+ Name: tagMessages,
Description: "Web form definitions, received messages, operator replies, and spam filters for the active workspace.",
})
streamGroup.WithBearerAuth()
@@ -86,7 +86,7 @@ func (r *Router) messageWorkspaceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodGet,
- Path: "/forms/{id:int}",
+ Path: pathFormByID,
Handler: okapi.H(r.h.form.Get),
Group: opsGroup,
Summary: "Get a form",
@@ -98,7 +98,7 @@ func (r *Router) messageWorkspaceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodPut,
- Path: "/forms/{id:int}",
+ Path: pathFormByID,
Handler: okapi.H(r.h.form.Update),
Group: opsGroup,
Summary: "Update a form",
@@ -111,7 +111,7 @@ func (r *Router) messageWorkspaceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodDelete,
- Path: "/forms/{id:int}",
+ Path: pathFormByID,
Handler: okapi.H(r.h.form.Delete),
Group: opsGroup,
Summary: "Delete a form",
diff --git a/internal/routes/oauth_routes.go b/internal/routes/oauth_routes.go
index 3a322a6..0b1e741 100644
--- a/internal/routes/oauth_routes.go
+++ b/internal/routes/oauth_routes.go
@@ -17,8 +17,8 @@ import (
func (r *Router) oauthRoutes() []okapi.RouteDefinition {
// Public OAuth routes (no auth required)
oauthPublic := r.v1.Group("/auth/oauth").WithTagInfo(okapi.GroupTag{
- Name: "OAuth",
- Description: "Single sign-on via external identity providers (Google, GitHub, generic OIDC). Covers public flow, user-account linking, admin provider config, and workspace SSO enforcement.",
+ Name: tagOAuth,
+ Description: descOAuth,
})
routes := make([]okapi.RouteDefinition, 0, 12)
@@ -69,8 +69,8 @@ func (r *Router) oauthRoutes() []okapi.RouteDefinition {
// Authenticated OAuth routes (linked accounts)
oauthUser := r.v1.Group("/users/me/oauth", r.mw.jwtOnly).WithTagInfo(okapi.GroupTag{
- Name: "OAuth",
- Description: "Single sign-on via external identity providers (Google, GitHub, generic OIDC). Covers public flow, user-account linking, admin provider config, and workspace SSO enforcement.",
+ Name: tagOAuth,
+ Description: descOAuth,
})
oauthUser.WithBearerAuth()
@@ -99,12 +99,12 @@ func (r *Router) oauthRoutes() []okapi.RouteDefinition {
// Admin OAuth provider management
oauthAdmin := r.v1.Group("/admin/oauth/providers", r.mw.jwtAdminAuth.Middleware).WithTagInfo(
okapi.GroupTag{
- Name: "Admin",
- Description: "Platform-level administration: users, workspaces, global settings, OAuth providers, and live event streams. Admin-only.",
+ Name: tagAdmin,
+ Description: descAdmin,
},
okapi.GroupTag{
- Name: "OAuth",
- Description: "Single sign-on via external identity providers (Google, GitHub, generic OIDC). Covers public flow, user-account linking, admin provider config, and workspace SSO enforcement.",
+ Name: tagOAuth,
+ Description: descOAuth,
},
)
oauthAdmin.WithBearerAuth()
@@ -157,12 +157,12 @@ func (r *Router) oauthRoutes() []okapi.RouteDefinition {
// Workspace SSO config
wsSSO := r.v1.Group("/workspaces/current/sso", r.mw.auth, r.mw.workspace).WithTagInfo(
okapi.GroupTag{
- Name: "Workspaces",
- Description: "Create workspaces, manage members and invitations, and configure workspace-scoped settings (including SSO).",
+ Name: tagWorkspaces,
+ Description: descWorkspacesWithSSO,
},
okapi.GroupTag{
- Name: "OAuth",
- Description: "Single sign-on via external identity providers (Google, GitHub, generic OIDC). Covers public flow, user-account linking, admin provider config, and workspace SSO enforcement.",
+ Name: tagOAuth,
+ Description: descOAuth,
},
)
wsSSO.WithBearerAuth()
diff --git a/internal/routes/paths.go b/internal/routes/paths.go
new file mode 100644
index 0000000..e665938
--- /dev/null
+++ b/internal/routes/paths.go
@@ -0,0 +1,28 @@
+// SPDX-FileCopyrightText: 2026 Jonas Kaninda
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+package routes
+
+// Route paths registered by more than one definition, typically the GET, PUT,
+// and DELETE of a single resource. They are named rather than repeated so a
+// change to one method's path cannot leave the others behind, which would turn
+// into a 404 on exactly one verb.
+//
+// They live together because goconst counts occurrences per package, not per
+// file, and several are shared across route files.
+const (
+ pathBounces = "/bounces"
+ pathSettings = "/settings"
+ pathSuppressions = "/suppressions"
+ pathWebhooks = "/webhooks"
+
+ pathCampaignByID = "/campaigns/{id:int}"
+ pathFormByID = "/forms/{id:int}"
+ pathPlanByID = "/plans/{id:int}"
+ pathServerByID = "/servers/{id:int}"
+ pathSMTPServerByID = "/smtp-servers/{id:int}"
+ pathSubscriberByID = "/subscribers/{id:int}"
+ pathSubscriberListByID = "/subscriber-lists/{id:int}"
+ pathSubscriberListMembers = "/subscriber-lists/{id:int}/members"
+ pathUnsubscribeListByID = "/unsubscribe-lists/{id:int}"
+)
diff --git a/internal/routes/tags.go b/internal/routes/tags.go
new file mode 100644
index 0000000..ec07380
--- /dev/null
+++ b/internal/routes/tags.go
@@ -0,0 +1,35 @@
+// SPDX-FileCopyrightText: 2026 Jonas Kaninda
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+package routes
+
+// OpenAPI tag names. A tag groups routes in the generated specification, so
+// every route in a group has to spell it identically — renaming one of a dozen
+// literals silently splits the group in two. They live here because several are
+// used from more than one route file.
+const (
+ tagAdmin = "Admin"
+ tagCampaigns = "Campaigns"
+ tagForms = "Forms"
+ tagInbound = "Inbound"
+ tagLanguages = "Languages"
+ tagMessages = "Messages"
+ tagOAuth = "OAuth"
+ tagSubscriberLists = "Subscriber Lists"
+ tagSubscribers = "Subscribers"
+ tagTemplateLocalizations = "Template Localizations"
+ tagTemplateVersions = "Template Versions"
+ tagTracking = "Tracking"
+ tagUnsubscribeLists = "Unsubscribe Lists"
+ tagUser = "User"
+ tagWorkspaceResources = "Workspace resources"
+ tagWorkspaces = "Workspaces"
+)
+
+// Tag descriptions that appear in more than one route file. Duplicated prose
+// drifts; a group whose description differs per file renders unpredictably.
+const (
+ descAdmin = "Platform-level administration: users, workspaces, global settings, OAuth providers, and live event streams. Admin-only."
+ descOAuth = "Single sign-on via external identity providers (Google, GitHub, generic OIDC). Covers public flow, user-account linking, admin provider config, and workspace SSO enforcement."
+ descWorkspacesWithSSO = "Create workspaces, manage members and invitations, and configure workspace-scoped settings (including SSO)."
+)
diff --git a/internal/routes/tracking_routes.go b/internal/routes/tracking_routes.go
index 0c332e0..ac5645a 100644
--- a/internal/routes/tracking_routes.go
+++ b/internal/routes/tracking_routes.go
@@ -17,7 +17,7 @@ func (r *Router) trackingRoutes() []okapi.RouteDefinition {
Method: http.MethodGet,
Path: "/t/o/{message_id:int}.gif",
Handler: okapi.H(r.h.tracking.OpenPixel),
- Tags: []string{"Tracking"},
+ Tags: []string{tagTracking},
Summary: "Open tracking pixel",
Options: []okapi.RouteOption{okapi.DocHide()},
},
@@ -25,7 +25,7 @@ func (r *Router) trackingRoutes() []okapi.RouteDefinition {
Method: http.MethodGet,
Path: "/t/c/{message_id:int}/{hash}",
Handler: okapi.H(r.h.tracking.ClickRedirect),
- Tags: []string{"Tracking"},
+ Tags: []string{tagTracking},
Summary: "Click tracking redirect",
Options: []okapi.RouteOption{okapi.DocHide()},
},
@@ -33,7 +33,7 @@ func (r *Router) trackingRoutes() []okapi.RouteDefinition {
Method: http.MethodGet,
Path: "/t/u/{token}",
Handler: okapi.H(r.h.tracking.UnsubscribePage),
- Tags: []string{"Tracking"},
+ Tags: []string{tagTracking},
Summary: "Unsubscribe page",
Options: []okapi.RouteOption{okapi.DocHide()},
},
@@ -41,7 +41,7 @@ func (r *Router) trackingRoutes() []okapi.RouteDefinition {
Method: http.MethodPost,
Path: "/t/u/{token}",
Handler: okapi.H(r.h.tracking.UnsubscribeConfirm),
- Tags: []string{"Tracking"},
+ Tags: []string{tagTracking},
Summary: "Confirm unsubscribe",
Options: []okapi.RouteOption{okapi.DocHide()},
},
@@ -49,7 +49,7 @@ func (r *Router) trackingRoutes() []okapi.RouteDefinition {
Method: http.MethodGet,
Path: "/t/u/tx/{token}",
Handler: okapi.H(r.h.tracking.TxUnsubscribePage),
- Tags: []string{"Tracking"},
+ Tags: []string{tagTracking},
Summary: "Transactional unsubscribe page",
Options: []okapi.RouteOption{okapi.DocHide()},
},
@@ -57,7 +57,7 @@ func (r *Router) trackingRoutes() []okapi.RouteDefinition {
Method: http.MethodPost,
Path: "/t/u/tx/{token}",
Handler: okapi.H(r.h.tracking.TxUnsubscribeConfirm),
- Tags: []string{"Tracking"},
+ Tags: []string{tagTracking},
Summary: "Transactional one-click unsubscribe (RFC 8058)",
Options: []okapi.RouteOption{okapi.DocHide()},
},
@@ -65,7 +65,7 @@ func (r *Router) trackingRoutes() []okapi.RouteDefinition {
Method: http.MethodGet,
Path: "/t/v/{token}",
Handler: okapi.H(r.h.tracking.WebView),
- Tags: []string{"Tracking"},
+ Tags: []string{tagTracking},
Summary: "View email in browser",
Options: []okapi.RouteOption{okapi.DocHide()},
},
@@ -96,7 +96,7 @@ func (r *Router) bounceWebhookRoutes() []okapi.RouteDefinition {
// scoped to the active workspace (workspace-only migration §7).
func (r *Router) trackingAnalyticsRoutes() []okapi.RouteDefinition {
wsGroup := r.v1.Group("/workspaces/current", r.mw.auth, r.mw.workspace).WithTagInfo(okapi.GroupTag{
- Name: "Campaigns",
+ Name: tagCampaigns,
Description: "Email campaign analytics — open, click, bounce, and engagement metrics for campaigns in the active workspace.",
})
wsGroup.WithBearerAuth()
diff --git a/internal/routes/user_routes.go b/internal/routes/user_routes.go
index d424d37..eeab713 100644
--- a/internal/routes/user_routes.go
+++ b/internal/routes/user_routes.go
@@ -15,7 +15,7 @@ import (
// userRoutes returns route definitions for all authenticated user endpoints.
func (r *Router) userRoutes() []okapi.RouteDefinition {
userGroup := r.v1.Group("/users/me", r.mw.jwtOnly, r.mw.optionalWorkspace).WithTagInfo(okapi.GroupTag{
- Name: "User",
+ Name: tagUser,
Description: "Manage the authenticated user: profile, password, API keys, notification preferences, and session. Requires a dashboard session — an API key cannot administer the account that issued it.",
})
userGroup.WithBearerAuth()
@@ -183,7 +183,7 @@ func (r *Router) userRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodGet,
- Path: "/settings",
+ Path: pathSettings,
Handler: r.h.userSetting.GetSettings,
Group: userGroup,
Summary: "Get user settings",
@@ -192,7 +192,7 @@ func (r *Router) userRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodPut,
- Path: "/settings",
+ Path: pathSettings,
Handler: okapi.H(r.h.userSetting.UpdateSettings),
Group: userGroup,
Summary: "Update user settings",
diff --git a/internal/routes/workspace_resource_routes.go b/internal/routes/workspace_resource_routes.go
index a2df8c9..8948c02 100644
--- a/internal/routes/workspace_resource_routes.go
+++ b/internal/routes/workspace_resource_routes.go
@@ -15,7 +15,7 @@ import (
func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
opsGroup := r.v1.Group("/workspaces/current", r.mw.auth, r.mw.workspace).WithTagInfo(okapi.GroupTag{
- Name: "Workspace resources",
+ Name: tagWorkspaceResources,
Description: "Operational resources scoped to the active workspace: sending, templates, stylesheets, languages, API keys, contacts, subscribers, campaigns, domains, SMTP servers, webhooks, suppressions, and workspace analytics. Authenticated with a dashboard session or an API key bound to the workspace.",
})
opsGroup.WithBearerAuth()
@@ -255,7 +255,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/templates",
Handler: okapi.H(r.h.template.Create),
Group: opsGroup,
- Tags: []string{"User"},
+ Tags: []string{tagUser},
Summary: "Create template",
Request: &handlers.CreateTemplateRequest{},
Options: []okapi.RouteOption{
@@ -303,7 +303,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/templates/{id:int}",
Handler: okapi.H(r.h.template.Delete),
Group: opsGroup,
- Tags: []string{"User"},
+ Tags: []string{tagUser},
Summary: "Delete template",
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Template ID"),
@@ -379,7 +379,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/templates/{id:int}/versions",
Handler: okapi.H(r.h.version.List),
Group: opsGroup,
- Tags: []string{"Template Versions"},
+ Tags: []string{tagTemplateVersions},
Summary: "List template versions",
Response: &dto.Response[[]models.TemplateVersion]{},
Options: []okapi.RouteOption{
@@ -392,7 +392,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/templates/{id:int}/versions",
Handler: okapi.H(r.h.version.Create),
Group: opsGroup,
- Tags: []string{"Template Versions"},
+ Tags: []string{tagTemplateVersions},
Summary: "Create template version",
Request: &handlers.CreateVersionRequest{},
Options: []okapi.RouteOption{
@@ -406,7 +406,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/templates/{id:int}/versions/{versionId:int}",
Handler: okapi.H(r.h.version.Update),
Group: opsGroup,
- Tags: []string{"Template Versions"},
+ Tags: []string{tagTemplateVersions},
Summary: "Update template version",
Request: &handlers.UpdateVersionRequest{},
Response: &dto.Response[models.TemplateVersion]{},
@@ -421,7 +421,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/templates/{id:int}/activate/{versionId:int}",
Handler: okapi.H(r.h.version.Activate),
Group: opsGroup,
- Tags: []string{"Template Versions"},
+ Tags: []string{tagTemplateVersions},
Summary: "Activate template version",
Response: &dto.Response[models.Template]{},
Options: []okapi.RouteOption{
@@ -435,7 +435,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/templates/{id:int}/versions/{versionId:int}",
Handler: okapi.H(r.h.version.Delete),
Group: opsGroup,
- Tags: []string{"Template Versions"},
+ Tags: []string{tagTemplateVersions},
Summary: "Delete template version",
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Template ID"),
@@ -449,7 +449,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/templates/{id:int}/versions/{versionId:int}/localizations",
Handler: okapi.H(r.h.localization.List),
Group: opsGroup,
- Tags: []string{"Template Localizations"},
+ Tags: []string{tagTemplateLocalizations},
Summary: "List localizations for a version",
Response: &dto.Response[[]models.TemplateLocalization]{},
Options: []okapi.RouteOption{
@@ -463,7 +463,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/templates/{id:int}/versions/{versionId:int}/localizations",
Handler: okapi.H(r.h.localization.Create),
Group: opsGroup,
- Tags: []string{"Template Localizations"},
+ Tags: []string{tagTemplateLocalizations},
Summary: "Create localization",
Request: &handlers.CreateLocalizationRequest{},
Options: []okapi.RouteOption{
@@ -479,7 +479,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/localizations/{localizationId:int}",
Handler: okapi.H(r.h.localization.Update),
Group: opsGroup,
- Tags: []string{"Template Localizations"},
+ Tags: []string{tagTemplateLocalizations},
Summary: "Update localization",
Request: &handlers.UpdateLocalizationRequest{},
Response: &dto.Response[models.TemplateLocalization]{},
@@ -493,7 +493,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/localizations/{localizationId:int}",
Handler: okapi.H(r.h.localization.Delete),
Group: opsGroup,
- Tags: []string{"Template Localizations"},
+ Tags: []string{tagTemplateLocalizations},
Summary: "Delete localization",
Options: []okapi.RouteOption{
okapi.DocPathParam("localizationId", "integer", "Localization ID"),
@@ -506,7 +506,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/templates/{id:int}/versions/{versionId:int}/preview",
Handler: okapi.H(r.h.localization.Preview),
Group: opsGroup,
- Tags: []string{"Template Localizations"},
+ Tags: []string{tagTemplateLocalizations},
Summary: "Preview localized template",
Description: "Render a specific language version of a template with sample data",
Request: &handlers.PreviewLocalizationRequest{},
@@ -522,7 +522,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/languages",
Handler: okapi.H(r.h.language.Create),
Group: opsGroup,
- Tags: []string{"Languages"},
+ Tags: []string{tagLanguages},
Summary: "Create language",
Request: &handlers.CreateLanguageRequest{},
Options: []okapi.RouteOption{
@@ -535,7 +535,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/languages",
Handler: okapi.H(r.h.language.List),
Group: opsGroup,
- Tags: []string{"Languages"},
+ Tags: []string{tagLanguages},
Summary: "List languages",
Request: &handlers.ListRequest{},
Response: &dto.PageableResponse[models.Language]{},
@@ -545,7 +545,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/languages/{id:int}",
Handler: okapi.H(r.h.language.Update),
Group: opsGroup,
- Tags: []string{"Languages"},
+ Tags: []string{tagLanguages},
Summary: "Update language",
Request: &handlers.UpdateLanguageRequest{},
Response: &dto.Response[models.Language]{},
@@ -559,7 +559,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/languages/{id:int}",
Handler: okapi.H(r.h.language.Delete),
Group: opsGroup,
- Tags: []string{"Languages"},
+ Tags: []string{tagLanguages},
Summary: "Delete language",
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Language ID"),
@@ -572,7 +572,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/stylesheets",
Handler: okapi.H(r.h.stylesheet.Create),
Group: opsGroup,
- Tags: []string{"User"},
+ Tags: []string{tagUser},
Summary: "Create stylesheet",
Request: &handlers.CreateStyleSheetRequest{},
Options: []okapi.RouteOption{
@@ -607,7 +607,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/stylesheets/{id:int}",
Handler: okapi.H(r.h.stylesheet.Delete),
Group: opsGroup,
- Tags: []string{"User"},
+ Tags: []string{tagUser},
Summary: "Delete stylesheet",
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "StyleSheet ID"),
@@ -620,7 +620,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/smtp-servers",
Handler: okapi.H(r.h.smtp.Create),
Group: opsGroup,
- Tags: []string{"User"},
+ Tags: []string{tagUser},
Summary: "Add SMTP server",
Request: &handlers.CreateSMTPRequest{},
Options: []okapi.RouteOption{
@@ -638,7 +638,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodGet,
- Path: "/smtp-servers/{id:int}",
+ Path: pathSMTPServerByID,
Handler: okapi.H(r.h.smtp.Get),
Group: opsGroup,
Summary: "Get SMTP server",
@@ -651,7 +651,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodPut,
- Path: "/smtp-servers/{id:int}",
+ Path: pathSMTPServerByID,
Handler: okapi.H(r.h.smtp.Update),
Group: opsGroup,
Summary: "Update SMTP server",
@@ -664,10 +664,10 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodDelete,
- Path: "/smtp-servers/{id:int}",
+ Path: pathSMTPServerByID,
Handler: okapi.H(r.h.smtp.Delete),
Group: opsGroup,
- Tags: []string{"User"},
+ Tags: []string{tagUser},
Summary: "Delete SMTP server",
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "SMTP server ID"),
@@ -689,10 +689,10 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodPost,
- Path: "/webhooks",
+ Path: pathWebhooks,
Handler: okapi.H(r.h.webhook.Create),
Group: opsGroup,
- Tags: []string{"User"},
+ Tags: []string{tagUser},
Summary: "Create webhook",
Request: &handlers.CreateWebhookRequest{},
Options: []okapi.RouteOption{
@@ -701,7 +701,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodGet,
- Path: "/webhooks",
+ Path: pathWebhooks,
Handler: okapi.H(r.h.webhook.List),
Group: opsGroup,
Summary: "List webhooks",
@@ -713,7 +713,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/webhooks/{id:int}",
Handler: okapi.H(r.h.webhook.Delete),
Group: opsGroup,
- Tags: []string{"User"},
+ Tags: []string{tagUser},
Summary: "Delete webhook",
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Webhook ID"),
@@ -769,7 +769,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/domains/{id:int}",
Handler: okapi.H(r.h.domain.Delete),
Group: opsGroup,
- Tags: []string{"User"},
+ Tags: []string{tagUser},
Summary: "Delete domain",
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Domain ID"),
@@ -792,7 +792,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodPost,
- Path: "/bounces",
+ Path: pathBounces,
Handler: okapi.H(r.h.bounce.Record),
Group: opsGroup,
Summary: "Record a bounce",
@@ -804,7 +804,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodGet,
- Path: "/bounces",
+ Path: pathBounces,
Handler: okapi.H(r.h.bounce.List),
Group: opsGroup,
Summary: "List bounces",
@@ -813,10 +813,10 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodPost,
- Path: "/suppressions",
+ Path: pathSuppressions,
Handler: okapi.H(r.h.suppression.Create),
Group: opsGroup,
- Tags: []string{"User"},
+ Tags: []string{tagUser},
Summary: "Add to suppression list",
Request: &handlers.CreateSuppressionRequest{},
Options: []okapi.RouteOption{
@@ -826,7 +826,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodGet,
- Path: "/suppressions",
+ Path: pathSuppressions,
Handler: okapi.H(r.h.suppression.List),
Group: opsGroup,
Summary: "List suppressed emails",
@@ -835,10 +835,10 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodDelete,
- Path: "/suppressions",
+ Path: pathSuppressions,
Handler: okapi.H(r.h.suppression.Delete),
Group: opsGroup,
- Tags: []string{"User"},
+ Tags: []string{tagUser},
Summary: "Remove from suppression list",
Request: &handlers.DeleteSuppressionRequest{},
Options: []okapi.RouteOption{
@@ -850,7 +850,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/unsubscribe-lists",
Handler: okapi.H(r.h.unsubscribeList.Create),
Group: opsGroup,
- Tags: []string{"Unsubscribe Lists"},
+ Tags: []string{tagUnsubscribeLists},
Summary: "Create unsubscribe list",
Request: &handlers.CreateUnsubscribeListRequest{},
Options: []okapi.RouteOption{
@@ -863,27 +863,27 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/unsubscribe-lists",
Handler: okapi.H(r.h.unsubscribeList.List),
Group: opsGroup,
- Tags: []string{"Unsubscribe Lists"},
+ Tags: []string{tagUnsubscribeLists},
Summary: "List unsubscribe lists",
Request: &handlers.ListRequest{},
Response: &dto.PageableResponse[models.UnsubscribeList]{},
},
{
Method: http.MethodGet,
- Path: "/unsubscribe-lists/{id:int}",
+ Path: pathUnsubscribeListByID,
Handler: okapi.H(r.h.unsubscribeList.Get),
Group: opsGroup,
- Tags: []string{"Unsubscribe Lists"},
+ Tags: []string{tagUnsubscribeLists},
Summary: "Get unsubscribe list",
Response: &dto.Response[models.UnsubscribeList]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "List ID")},
},
{
Method: http.MethodPut,
- Path: "/unsubscribe-lists/{id:int}",
+ Path: pathUnsubscribeListByID,
Handler: okapi.H(r.h.unsubscribeList.Update),
Group: opsGroup,
- Tags: []string{"Unsubscribe Lists"},
+ Tags: []string{tagUnsubscribeLists},
Summary: "Update unsubscribe list",
Request: &handlers.UpdateUnsubscribeListRequest{},
Response: &dto.Response[models.UnsubscribeList]{},
@@ -891,10 +891,10 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodDelete,
- Path: "/unsubscribe-lists/{id:int}",
+ Path: pathUnsubscribeListByID,
Handler: okapi.H(r.h.unsubscribeList.Delete),
Group: opsGroup,
- Tags: []string{"Unsubscribe Lists"},
+ Tags: []string{tagUnsubscribeLists},
Summary: "Delete unsubscribe list",
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "List ID"), okapi.DocResponse(204, nil)},
},
@@ -923,7 +923,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/subscribers",
Handler: okapi.H(r.h.subscriber.Create),
Group: opsGroup,
- Tags: []string{"Subscribers"},
+ Tags: []string{tagSubscribers},
Summary: "Create subscriber",
Request: &handlers.CreateSubscriberRequest{},
Options: []okapi.RouteOption{okapi.DocResponse(201, &dto.Response[models.Subscriber]{})},
@@ -933,27 +933,27 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/subscribers",
Handler: okapi.H(r.h.subscriber.List),
Group: opsGroup,
- Tags: []string{"Subscribers"},
+ Tags: []string{tagSubscribers},
Summary: "List subscribers",
Request: &handlers.ListSubscribersRequest{},
Response: &dto.PageableResponse[models.Subscriber]{},
},
{
Method: http.MethodGet,
- Path: "/subscribers/{id:int}",
+ Path: pathSubscriberByID,
Handler: okapi.H(r.h.subscriber.Get),
Group: opsGroup,
- Tags: []string{"Subscribers"},
+ Tags: []string{tagSubscribers},
Summary: "Get subscriber",
Response: &dto.Response[models.Subscriber]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Subscriber ID")},
},
{
Method: http.MethodPut,
- Path: "/subscribers/{id:int}",
+ Path: pathSubscriberByID,
Handler: okapi.H(r.h.subscriber.Update),
Group: opsGroup,
- Tags: []string{"Subscribers"},
+ Tags: []string{tagSubscribers},
Summary: "Update subscriber",
Request: &handlers.UpdateSubscriberRequest{},
Response: &dto.Response[models.Subscriber]{},
@@ -961,10 +961,10 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodDelete,
- Path: "/subscribers/{id:int}",
+ Path: pathSubscriberByID,
Handler: okapi.H(r.h.subscriber.Delete),
Group: opsGroup,
- Tags: []string{"Subscribers"},
+ Tags: []string{tagSubscribers},
Summary: "Delete subscriber",
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Subscriber ID"), okapi.DocResponse(204, nil)},
},
@@ -973,7 +973,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/subscribers/import/json",
Handler: okapi.H(r.h.subscriber.BulkImportJSON),
Group: opsGroup,
- Tags: []string{"Subscribers"},
+ Tags: []string{tagSubscribers},
Summary: "Bulk import subscribers (JSON)",
Request: &handlers.BulkImportSubscribersRequest{},
Response: &dto.Response[handlers.BulkImportResult]{},
@@ -983,7 +983,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/subscribers/import/csv",
Handler: r.h.subscriber.BulkImportCSV,
Group: opsGroup,
- Tags: []string{"Subscribers"},
+ Tags: []string{tagSubscribers},
Summary: "Bulk import subscribers (CSV)",
Description: "Upload a CSV file with optional column_mapping JSON field",
Response: &dto.Response[handlers.BulkImportResult]{},
@@ -993,7 +993,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/subscriber-lists",
Handler: okapi.H(r.h.subscriberList.Create),
Group: opsGroup,
- Tags: []string{"Subscriber Lists"},
+ Tags: []string{tagSubscriberLists},
Summary: "Create subscriber list",
Request: &handlers.CreateSubscriberListRequest{},
Options: []okapi.RouteOption{okapi.DocResponse(201, &dto.Response[models.SubscriberList]{})},
@@ -1003,27 +1003,27 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/subscriber-lists",
Handler: okapi.H(r.h.subscriberList.List),
Group: opsGroup,
- Tags: []string{"Subscriber Lists"},
+ Tags: []string{tagSubscriberLists},
Summary: "List subscriber lists",
Request: &handlers.ListRequest{},
Response: &dto.PageableResponse[handlers.SubscriberListWithCount]{},
},
{
Method: http.MethodGet,
- Path: "/subscriber-lists/{id:int}",
+ Path: pathSubscriberListByID,
Handler: okapi.H(r.h.subscriberList.Get),
Group: opsGroup,
- Tags: []string{"Subscriber Lists"},
+ Tags: []string{tagSubscriberLists},
Summary: "Get subscriber list",
Response: &dto.Response[handlers.SubscriberListWithCount]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "List ID")},
},
{
Method: http.MethodPut,
- Path: "/subscriber-lists/{id:int}",
+ Path: pathSubscriberListByID,
Handler: okapi.H(r.h.subscriberList.Update),
Group: opsGroup,
- Tags: []string{"Subscriber Lists"},
+ Tags: []string{tagSubscriberLists},
Summary: "Update subscriber list",
Request: &handlers.UpdateSubscriberListRequest{},
Response: &dto.Response[models.SubscriberList]{},
@@ -1031,19 +1031,19 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodDelete,
- Path: "/subscriber-lists/{id:int}",
+ Path: pathSubscriberListByID,
Handler: okapi.H(r.h.subscriberList.Delete),
Group: opsGroup,
- Tags: []string{"Subscriber Lists"},
+ Tags: []string{tagSubscriberLists},
Summary: "Delete subscriber list",
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "List ID"), okapi.DocResponse(204, nil)},
},
{
Method: http.MethodPost,
- Path: "/subscriber-lists/{id:int}/members",
+ Path: pathSubscriberListMembers,
Handler: okapi.H(r.h.subscriberList.AddMember),
Group: opsGroup,
- Tags: []string{"Subscriber Lists"},
+ Tags: []string{tagSubscriberLists},
Summary: "Add subscriber to list",
Request: &handlers.AddSubscriberToListRequest{},
Response: &dto.Response[okapi.M]{},
@@ -1051,10 +1051,10 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodDelete,
- Path: "/subscriber-lists/{id:int}/members",
+ Path: pathSubscriberListMembers,
Handler: okapi.H(r.h.subscriberList.RemoveMember),
Group: opsGroup,
- Tags: []string{"Subscriber Lists"},
+ Tags: []string{tagSubscriberLists},
Summary: "Remove subscriber from list",
Request: &handlers.RemoveSubscriberFromListRequest{},
Response: &dto.Response[okapi.M]{},
@@ -1062,10 +1062,10 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodGet,
- Path: "/subscriber-lists/{id:int}/members",
+ Path: pathSubscriberListMembers,
Handler: okapi.H(r.h.subscriberList.ListMembers),
Group: opsGroup,
- Tags: []string{"Subscriber Lists"},
+ Tags: []string{tagSubscriberLists},
Summary: "List members of subscriber list",
Request: &handlers.ListSubscriberListMembersRequest{},
Response: &dto.PageableResponse[models.Subscriber]{},
@@ -1076,7 +1076,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/subscriber-lists/preview-segment",
Handler: okapi.H(r.h.subscriberList.PreviewSegment),
Group: opsGroup,
- Tags: []string{"Subscriber Lists"},
+ Tags: []string{tagSubscriberLists},
Summary: "Preview segment count",
Description: "Evaluate filter rules and return the number of matching subscribers",
Request: &handlers.PreviewSegmentRequest{},
@@ -1087,7 +1087,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/subscriber-lists/{id:int}/unsubscribe",
Handler: okapi.H(r.h.subscriberList.UnsubscribeByEmail),
Group: opsGroup,
- Tags: []string{"Subscriber Lists"},
+ Tags: []string{tagSubscriberLists},
Summary: "Unsubscribe an email from a list",
Description: "API-key-accessible list opt-out. Idempotent. Does not change global subscriber status.",
Request: &handlers.ListUnsubscribeByEmailRequest{},
@@ -1099,7 +1099,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/subscriber-lists/{id:int}/resubscribe",
Handler: okapi.H(r.h.subscriberList.ResubscribeByEmail),
Group: opsGroup,
- Tags: []string{"Subscriber Lists"},
+ Tags: []string{tagSubscriberLists},
Summary: "Re-subscribe an email to a list",
Description: "Reverses a list-scoped opt-out and re-adds to the list (static lists). Idempotent.",
Request: &handlers.ListResubscribeByEmailRequest{},
@@ -1111,7 +1111,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/campaigns",
Handler: okapi.H(r.h.campaign.Create),
Group: opsGroup,
- Tags: []string{"Campaigns"},
+ Tags: []string{tagCampaigns},
Summary: "Create campaign",
Request: &handlers.CreateCampaignRequest{},
Options: []okapi.RouteOption{okapi.DocResponse(201, &dto.Response[models.Campaign]{})},
@@ -1121,27 +1121,27 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/campaigns",
Handler: okapi.H(r.h.campaign.List),
Group: opsGroup,
- Tags: []string{"Campaigns"},
+ Tags: []string{tagCampaigns},
Summary: "List campaigns",
Request: &handlers.ListCampaignsRequest{},
Response: &dto.PageableResponse[handlers.CampaignWithStats]{},
},
{
Method: http.MethodGet,
- Path: "/campaigns/{id:int}",
+ Path: pathCampaignByID,
Handler: okapi.H(r.h.campaign.Get),
Group: opsGroup,
- Tags: []string{"Campaigns"},
+ Tags: []string{tagCampaigns},
Summary: "Get campaign",
Response: &dto.Response[handlers.CampaignWithStats]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Campaign ID")},
},
{
Method: http.MethodPut,
- Path: "/campaigns/{id:int}",
+ Path: pathCampaignByID,
Handler: okapi.H(r.h.campaign.Update),
Group: opsGroup,
- Tags: []string{"Campaigns"},
+ Tags: []string{tagCampaigns},
Summary: "Update campaign",
Request: &handlers.UpdateCampaignRequest{},
Response: &dto.Response[models.Campaign]{},
@@ -1149,10 +1149,10 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodDelete,
- Path: "/campaigns/{id:int}",
+ Path: pathCampaignByID,
Handler: okapi.H(r.h.campaign.Delete),
Group: opsGroup,
- Tags: []string{"Campaigns"},
+ Tags: []string{tagCampaigns},
Summary: "Delete campaign",
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Campaign ID"), okapi.DocResponse(204, nil)},
},
@@ -1161,7 +1161,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/campaigns/{id:int}/send",
Handler: okapi.H(r.h.campaign.Send),
Group: opsGroup,
- Tags: []string{"Campaigns"},
+ Tags: []string{tagCampaigns},
Summary: "Send campaign",
Response: &dto.Response[models.Campaign]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Campaign ID")},
@@ -1171,7 +1171,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/campaigns/{id:int}/pause",
Handler: okapi.H(r.h.campaign.Pause),
Group: opsGroup,
- Tags: []string{"Campaigns"},
+ Tags: []string{tagCampaigns},
Summary: "Pause campaign",
Response: &dto.Response[models.Campaign]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Campaign ID")},
@@ -1181,7 +1181,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/campaigns/{id:int}/resume",
Handler: okapi.H(r.h.campaign.Resume),
Group: opsGroup,
- Tags: []string{"Campaigns"},
+ Tags: []string{tagCampaigns},
Summary: "Resume campaign",
Response: &dto.Response[models.Campaign]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Campaign ID")},
@@ -1191,7 +1191,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/campaigns/{id:int}/cancel",
Handler: okapi.H(r.h.campaign.Cancel),
Group: opsGroup,
- Tags: []string{"Campaigns"},
+ Tags: []string{tagCampaigns},
Summary: "Cancel campaign",
Response: &dto.Response[models.Campaign]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Campaign ID")},
@@ -1201,7 +1201,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/campaigns/{id:int}/duplicate",
Handler: okapi.H(r.h.campaign.Duplicate),
Group: opsGroup,
- Tags: []string{"Campaigns"},
+ Tags: []string{tagCampaigns},
Summary: "Duplicate campaign",
Response: &dto.Response[models.Campaign]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Campaign ID")},
@@ -1211,7 +1211,7 @@ func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
Path: "/campaigns/{id:int}/messages",
Handler: okapi.H(r.h.campaign.ListMessages),
Group: opsGroup,
- Tags: []string{"Campaigns"},
+ Tags: []string{tagCampaigns},
Summary: "List campaign messages",
Request: &handlers.ListCampaignMessagesRequest{},
Response: &dto.PageableResponse[models.CampaignMessage]{},
diff --git a/internal/routes/workspace_routes.go b/internal/routes/workspace_routes.go
index 383df82..567bb00 100644
--- a/internal/routes/workspace_routes.go
+++ b/internal/routes/workspace_routes.go
@@ -17,7 +17,7 @@ import (
func (r *Router) workspaceRoutes() []okapi.RouteDefinition {
// Routes that don't require workspace context (user-level)
userGroup := r.v1.Group("/workspaces", r.mw.jwtOnly).WithTagInfo(okapi.GroupTag{
- Name: "Workspaces",
+ Name: tagWorkspaces,
Description: "Create workspaces, manage members and invitations, and configure workspace-scoped settings. Creating and listing workspaces is account-level and requires a dashboard session.",
})
userGroup.WithBearerAuth()
@@ -52,8 +52,8 @@ func (r *Router) workspaceRoutes() []okapi.RouteDefinition {
// Workspace-scoped routes (require workspace context via middleware)
wsGroup := r.v1.Group("/workspaces/current", r.mw.auth, r.mw.workspace).WithTagInfo(okapi.GroupTag{
- Name: "Workspaces",
- Description: "Create workspaces, manage members and invitations, and configure workspace-scoped settings (including SSO).",
+ Name: tagWorkspaces,
+ Description: descWorkspacesWithSSO,
})
wsGroup.WithBearerAuth()
@@ -199,7 +199,7 @@ func (r *Router) workspaceRoutes() []okapi.RouteDefinition {
// Operational settings
{
Method: http.MethodGet,
- Path: "/settings",
+ Path: pathSettings,
Handler: r.h.workspaceSetting.GetSettings,
Group: wsGroup,
Summary: "Get workspace settings",
@@ -209,7 +209,7 @@ func (r *Router) workspaceRoutes() []okapi.RouteDefinition {
},
{
Method: http.MethodPut,
- Path: "/settings",
+ Path: pathSettings,
Handler: okapi.H(r.h.workspaceSetting.UpdateSettings),
Group: wsGroup,
Middlewares: []okapi.Middleware{middlewares.RequireWorkspaceRole(models.WorkspaceRoleAdmin)},
@@ -307,8 +307,8 @@ func (r *Router) workspaceRoutes() []okapi.RouteDefinition {
// User-level invitation actions (no workspace context needed)
invGroup := r.v1.Group("/invitations", r.mw.jwtOnly).WithTagInfo(okapi.GroupTag{
- Name: "Workspaces",
- Description: "Create workspaces, manage members and invitations, and configure workspace-scoped settings (including SSO).",
+ Name: tagWorkspaces,
+ Description: descWorkspacesWithSSO,
})
invGroup.WithBearerAuth()
diff --git a/internal/services/domain/verifier.go b/internal/services/domain/verifier.go
index ea5c837..7abdbc0 100644
--- a/internal/services/domain/verifier.go
+++ b/internal/services/domain/verifier.go
@@ -10,6 +10,9 @@ import (
"github.com/goposta/posta/internal/models"
)
+// recordTypeTXT is the DNS record type every verification check reads.
+const recordTypeTXT = "TXT"
+
// VerificationResult holds the outcome of DNS record checks.
type VerificationResult struct {
OwnershipVerified bool `json:"ownership_verified"`
@@ -39,12 +42,12 @@ type DNSRecord struct {
func RequiredRecords(d *models.Domain) *DNSRecords {
return &DNSRecords{
Verification: DNSRecord{
- Type: "TXT",
+ Type: recordTypeTXT,
Host: d.Domain,
Value: "posta-verification=" + d.VerificationToken,
},
SPF: DNSRecord{
- Type: "TXT",
+ Type: recordTypeTXT,
Host: d.Domain,
Value: "v=spf1 include:_spf.posta ~all",
},
@@ -54,7 +57,7 @@ func RequiredRecords(d *models.Domain) *DNSRecords {
Value: "posta._domainkey.posta",
},
DMARC: DNSRecord{
- Type: "TXT",
+ Type: recordTypeTXT,
Host: "_dmarc." + d.Domain,
Value: "v=DMARC1; p=none; rua=mailto:dmarc@" + d.Domain,
},
diff --git a/internal/services/email/provider.go b/internal/services/email/provider.go
index 1978119..5568a6a 100644
--- a/internal/services/email/provider.go
+++ b/internal/services/email/provider.go
@@ -8,68 +8,84 @@ import (
"strings"
)
-const ProviderOther = "Other"
+// Mailbox provider names, as reported by deliverability analytics. Named so the
+// domain table below cannot drift into "Outlook" in one row and "outlook" in
+// another, which would split one provider into two buckets in the breakdown.
+const (
+ ProviderAOL = "AOL"
+ ProviderAppleICloud = "Apple iCloud"
+ ProviderFastmail = "Fastmail"
+ ProviderGMX = "GMX"
+ ProviderGmail = "Gmail"
+ ProviderGoogleWorkspace = "Google Workspace"
+ ProviderOutlook = "Outlook"
+ ProviderProton = "Proton"
+ ProviderYahoo = "Yahoo"
+ ProviderYandex = "Yandex"
+ ProviderZoho = "Zoho"
+ ProviderOther = "Other"
+)
var providerByDomain = map[string]string{
// Gmail (consumer)
- "gmail.com": "Gmail",
- "googlemail.com": "Gmail",
+ "gmail.com": ProviderGmail,
+ "googlemail.com": ProviderGmail,
// Google Workspace primary domain
- "google.com": "Google Workspace",
+ "google.com": ProviderGoogleWorkspace,
// Outlook / Microsoft consumer
- "outlook.com": "Outlook",
- "hotmail.com": "Outlook",
- "live.com": "Outlook",
- "msn.com": "Outlook",
- "outlook.co.uk": "Outlook",
- "hotmail.co.uk": "Outlook",
- "live.co.uk": "Outlook",
- "hotmail.fr": "Outlook",
- "outlook.fr": "Outlook",
- "live.fr": "Outlook",
+ "outlook.com": ProviderOutlook,
+ "hotmail.com": ProviderOutlook,
+ "live.com": ProviderOutlook,
+ "msn.com": ProviderOutlook,
+ "outlook.co.uk": ProviderOutlook,
+ "hotmail.co.uk": ProviderOutlook,
+ "live.co.uk": ProviderOutlook,
+ "hotmail.fr": ProviderOutlook,
+ "outlook.fr": ProviderOutlook,
+ "live.fr": ProviderOutlook,
// Yahoo
- "yahoo.com": "Yahoo",
- "yahoo.co.uk": "Yahoo",
- "yahoo.fr": "Yahoo",
- "yahoo.de": "Yahoo",
- "yahoo.co.jp": "Yahoo",
- "yahoo.ca": "Yahoo",
- "ymail.com": "Yahoo",
- "rocketmail.com": "Yahoo",
+ "yahoo.com": ProviderYahoo,
+ "yahoo.co.uk": ProviderYahoo,
+ "yahoo.fr": ProviderYahoo,
+ "yahoo.de": ProviderYahoo,
+ "yahoo.co.jp": ProviderYahoo,
+ "yahoo.ca": ProviderYahoo,
+ "ymail.com": ProviderYahoo,
+ "rocketmail.com": ProviderYahoo,
// Apple iCloud
- "icloud.com": "Apple iCloud",
- "me.com": "Apple iCloud",
- "mac.com": "Apple iCloud",
+ "icloud.com": ProviderAppleICloud,
+ "me.com": ProviderAppleICloud,
+ "mac.com": ProviderAppleICloud,
// Proton
- "proton.me": "Proton",
- "protonmail.com": "Proton",
- "pm.me": "Proton",
+ "proton.me": ProviderProton,
+ "protonmail.com": ProviderProton,
+ "pm.me": ProviderProton,
// AOL
- "aol.com": "AOL",
+ "aol.com": ProviderAOL,
// GMX / mail.com
- "gmx.com": "GMX",
- "gmx.net": "GMX",
- "gmx.de": "GMX",
- "mail.com": "GMX",
+ "gmx.com": ProviderGMX,
+ "gmx.net": ProviderGMX,
+ "gmx.de": ProviderGMX,
+ "mail.com": ProviderGMX,
// Zoho
- "zoho.com": "Zoho",
- "zohomail.com": "Zoho",
+ "zoho.com": ProviderZoho,
+ "zohomail.com": ProviderZoho,
// Fastmail
- "fastmail.com": "Fastmail",
- "fastmail.fm": "Fastmail",
+ "fastmail.com": ProviderFastmail,
+ "fastmail.fm": ProviderFastmail,
// Yandex
- "yandex.ru": "Yandex",
- "yandex.com": "Yandex",
+ "yandex.ru": ProviderYandex,
+ "yandex.com": ProviderYandex,
}
// providerBySuffix catches subdomain-style matches (e.g. "mail.google.com").
diff --git a/internal/services/email/service.go b/internal/services/email/service.go
index 573a8a8..2607c57 100644
--- a/internal/services/email/service.go
+++ b/internal/services/email/service.go
@@ -291,6 +291,10 @@ type Unsubscribe struct {
OneClick bool `json:"one_click,omitempty" doc:"Emit 'List-Unsubscribe-Post: List-Unsubscribe=One-Click' (RFC 8058). Applies to the https URL target only; the caller-managed path requires an https url. Implied true on the Posta-managed (list_id) path."`
}
+// errRecipientSuppressed is the reason recorded on an email, and reported in a
+// batch result, when the recipient is on the workspace suppression list.
+const errRecipientSuppressed = "recipient is suppressed"
+
type SendRequest struct {
From string `json:"from" required:"true" doc:"Sender address. Accepts a plain address ([email protected]) or RFC 5322 display-name format (Acme <[email protected]>)."`
To []string `json:"to" required:"true" minItems:"1" doc:"Recipient addresses. Each accepts a plain address or RFC 5322 display-name format (e.g. Jonas <[email protected]>)."`
@@ -693,7 +697,7 @@ func (s *Service) Send(ctx context.Context, userID, apiKeyID uint, workspaceID *
Subject: req.Subject,
TemplateName: req.TemplateName,
Status: models.EmailStatusSuppressed,
- ErrorMessage: "recipient is suppressed",
+ ErrorMessage: errRecipientSuppressed,
Provider: ClassifyProvider(addr),
}
_ = s.emailRepo.Create(em)
@@ -1006,7 +1010,7 @@ func (s *Service) SendBatch(ctx context.Context, userID, apiKeyID uint, workspac
Subject: req.Template,
TemplateName: tmpl.Name,
Status: models.EmailStatusSuppressed,
- ErrorMessage: "recipient is suppressed",
+ ErrorMessage: errRecipientSuppressed,
Provider: ClassifyProvider(recipient.Email),
}
_ = s.emailRepo.Create(em)
@@ -1016,7 +1020,7 @@ func (s *Service) SendBatch(ctx context.Context, userID, apiKeyID uint, workspac
Email: recipient.Email,
ID: em.UUID,
Status: models.EmailStatusSuppressed,
- Error: "recipient is suppressed",
+ Error: errRecipientSuppressed,
})
continue
}
diff --git a/internal/services/seeder/seeder.go b/internal/services/seeder/seeder.go
index 299c02c..4fa876a 100644
--- a/internal/services/seeder/seeder.go
+++ b/internal/services/seeder/seeder.go
@@ -54,6 +54,10 @@ type templateDef struct {
// seedTemplate creates a single template with a version and one localization
// per seedLanguages entry, loading each localized body from the embedded files.
+// sampleBrand fills the {{ company }} and {{ product }} placeholders in the
+// seeded templates' preview data.
+const sampleBrand = "Posta"
+
func (s *Seeder) seedTemplate(workspaceID, userID uint, ssID uint, def templateDef) {
b, _ := json.MarshalIndent(def.SampleData, "", " ")
sampleData := string(b)
@@ -179,8 +183,8 @@ func defaultTemplateDefs(userName string, year int, docsURL string) []templateDe
Description: "Welcome email introducing Posta and its features",
SampleData: okapi.M{
"name": userName,
- "product": "Posta",
- "company": "Posta",
+ "product": sampleBrand,
+ "company": sampleBrand,
"year": year,
"docs": docsURL,
"features": []string{
@@ -219,7 +223,7 @@ func defaultTemplateDefs(userName string, year int, docsURL string) []templateDe
Description: "Transactional email for password reset requests",
SampleData: okapi.M{
"name": userName,
- "company": "Posta",
+ "company": sampleBrand,
"year": year,
"resetLink": "https://example.com/reset?token=abc123",
"expiry": "1 hour",
@@ -237,7 +241,7 @@ func defaultTemplateDefs(userName string, year int, docsURL string) []templateDe
Description: "Order confirmation email with item details and total",
SampleData: okapi.M{
"name": userName,
- "company": "Posta",
+ "company": sampleBrand,
"year": year,
"orderNumber": "10042",
"orderDate": "April 21, 2026",
@@ -260,7 +264,7 @@ func defaultTemplateDefs(userName string, year int, docsURL string) []templateDe
Description: "Monthly newsletter with articles and unsubscribe link",
SampleData: okapi.M{
"name": userName,
- "company": "Posta",
+ "company": sampleBrand,
"year": year,
"month": "April",
"articles": []map[string]string{
@@ -295,7 +299,7 @@ func defaultTemplateDefs(userName string, year int, docsURL string) []templateDe
Description: "Confirm a new account's email address with a link and code",
SampleData: okapi.M{
"name": userName,
- "company": "Posta",
+ "company": sampleBrand,
"year": year,
"verifyLink": "https://example.com/verify?token=abc123",
"code": "492018",
@@ -314,7 +318,7 @@ func defaultTemplateDefs(userName string, year int, docsURL string) []templateDe
Description: "One-time passcode / magic-link login email",
SampleData: okapi.M{
"name": userName,
- "company": "Posta",
+ "company": sampleBrand,
"year": year,
"code": "731924",
"loginLink": "https://example.com/login?token=abc123",
@@ -333,7 +337,7 @@ func defaultTemplateDefs(userName string, year int, docsURL string) []templateDe
Description: "Payment receipt with line items, subtotal, tax, and total",
SampleData: okapi.M{
"name": userName,
- "company": "Posta",
+ "company": sampleBrand,
"year": year,
"invoiceNumber": "INV-2042",
"invoiceDate": "April 21, 2026",
@@ -359,7 +363,7 @@ func defaultTemplateDefs(userName string, year int, docsURL string) []templateDe
Description: "Invite a user to a workspace with an accept link and role",
SampleData: okapi.M{
"name": userName,
- "company": "Posta",
+ "company": sampleBrand,
"year": year,
"inviterName": "Jonas",
"workspaceName": "Acme Marketing",
diff --git a/internal/services/seeder/settings.go b/internal/services/seeder/settings.go
index 90215ff..9e5640e 100644
--- a/internal/services/seeder/settings.go
+++ b/internal/services/seeder/settings.go
@@ -19,28 +19,28 @@ func SeedDefaultSettings(repo *repositories.SettingRepository) {
}
defaults := []models.Setting{
- {Key: "registration_enabled", Value: "false", Type: "bool"},
- {Key: "require_email_verification", Value: "true", Type: "bool"},
- {Key: "require_domain_verification", Value: "true", Type: "bool"},
- {Key: "default_rate_limit_hourly", Value: "100", Type: "int"},
- {Key: "default_rate_limit_daily", Value: "1000", Type: "int"},
- {Key: "max_batch_size", Value: "100", Type: "int"},
- {Key: "max_attachment_size_mb", Value: "10", Type: "int"},
- {Key: "retention_days", Value: "30", Type: "int"},
- {Key: "email_body_retention_days", Value: retentionDays, Type: "int"},
- {Key: "email_attachment_retention_days", Value: retentionDays, Type: "int"},
- {Key: "global_bounce_threshold", Value: "5", Type: "int"},
- {Key: "smtp_timeout_seconds", Value: "30", Type: "int"},
- {Key: "maintenance_mode", Value: "false", Type: "bool"},
- {Key: "allowed_signup_domains", Value: "", Type: "string"},
- {Key: "two_factor_required", Value: "false", Type: "bool"},
- {Key: "login_rate_limit_count", Value: "10", Type: "int"},
- {Key: "login_rate_limit_window_minutes", Value: "15", Type: "int"},
- {Key: "audit_log_retention_days", Value: "90", Type: "int"},
- {Key: "webhook_delivery_retention_days", Value: "30", Type: "int"},
- {Key: "email_content_visibility", Value: "false", Type: "bool"},
- {Key: "custom_headers_enabled", Value: "false", Type: "bool"},
- {Key: "password_reset_enabled", Value: "false", Type: "bool"},
+ {Key: "registration_enabled", Value: models.SettingFalse, Type: models.SettingTypeBool},
+ {Key: "require_email_verification", Value: models.SettingTrue, Type: models.SettingTypeBool},
+ {Key: "require_domain_verification", Value: models.SettingTrue, Type: models.SettingTypeBool},
+ {Key: "default_rate_limit_hourly", Value: "100", Type: models.SettingTypeInt},
+ {Key: "default_rate_limit_daily", Value: "1000", Type: models.SettingTypeInt},
+ {Key: "max_batch_size", Value: "100", Type: models.SettingTypeInt},
+ {Key: "max_attachment_size_mb", Value: "10", Type: models.SettingTypeInt},
+ {Key: "retention_days", Value: "30", Type: models.SettingTypeInt},
+ {Key: "email_body_retention_days", Value: retentionDays, Type: models.SettingTypeInt},
+ {Key: "email_attachment_retention_days", Value: retentionDays, Type: models.SettingTypeInt},
+ {Key: "global_bounce_threshold", Value: "5", Type: models.SettingTypeInt},
+ {Key: "smtp_timeout_seconds", Value: "30", Type: models.SettingTypeInt},
+ {Key: "maintenance_mode", Value: models.SettingFalse, Type: models.SettingTypeBool},
+ {Key: "allowed_signup_domains", Value: "", Type: models.SettingTypeString},
+ {Key: "two_factor_required", Value: models.SettingFalse, Type: models.SettingTypeBool},
+ {Key: "login_rate_limit_count", Value: "10", Type: models.SettingTypeInt},
+ {Key: "login_rate_limit_window_minutes", Value: "15", Type: models.SettingTypeInt},
+ {Key: "audit_log_retention_days", Value: "90", Type: models.SettingTypeInt},
+ {Key: "webhook_delivery_retention_days", Value: "30", Type: models.SettingTypeInt},
+ {Key: "email_content_visibility", Value: models.SettingFalse, Type: models.SettingTypeBool},
+ {Key: "custom_headers_enabled", Value: models.SettingFalse, Type: models.SettingTypeBool},
+ {Key: "password_reset_enabled", Value: models.SettingFalse, Type: models.SettingTypeBool},
}
for i := range defaults {
diff --git a/internal/storage/migration/constraints.go b/internal/storage/migration/constraints.go
index 5e6cdeb..942205d 100644
--- a/internal/storage/migration/constraints.go
+++ b/internal/storage/migration/constraints.go
@@ -112,9 +112,11 @@ func rebuildUniqueIndexes(db *gorm.DB) {
column string
}
+ const colName = "name"
+
indexes := []indexDef{
- {"templates", "idx_user_template", "idx_workspace_template", "name"},
- {"style_sheets", "idx_user_stylesheet", "idx_workspace_stylesheet", "name"},
+ {"templates", "idx_user_template", "idx_workspace_template", colName},
+ {"style_sheets", "idx_user_stylesheet", "idx_workspace_stylesheet", colName},
{"contacts", "idx_user_email", "idx_workspace_email", "email"},
{"domains", "idx_user_domain", "idx_workspace_domain", "domain"},
{"languages", "idx_user_language", "idx_workspace_language", "code"},
diff --git a/internal/storage/migration/upgrade/settings.go b/internal/storage/migration/upgrade/settings.go
index 1205cbe..e4ab203 100644
--- a/internal/storage/migration/upgrade/settings.go
+++ b/internal/storage/migration/upgrade/settings.go
@@ -46,7 +46,7 @@ func upsertSetting(tx *gorm.DB, key, value string) error {
var existing models.Setting
err := tx.Where("key = ?", key).First(&existing).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
- return tx.Create(&models.Setting{Key: key, Value: value, Type: "string"}).Error
+ return tx.Create(&models.Setting{Key: key, Value: value, Type: models.SettingTypeString}).Error
}
if err != nil {
return err
@@ -66,5 +66,5 @@ func ensureSetting(tx *gorm.DB, key, value string) error {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}
- return tx.Create(&models.Setting{Key: key, Value: value, Type: "string"}).Error
+ return tx.Create(&models.Setting{Key: key, Value: value, Type: models.SettingTypeString}).Error
}
diff --git a/internal/storage/repositories/analytics_repo.go b/internal/storage/repositories/analytics_repo.go
index b038608..50bdf2f 100644
--- a/internal/storage/repositories/analytics_repo.go
+++ b/internal/storage/repositories/analytics_repo.go
@@ -4,6 +4,7 @@
package repositories
import (
+ "github.com/goposta/posta/internal/models"
"time"
"gorm.io/gorm"
@@ -131,7 +132,7 @@ func (r *AnalyticsRepository) DeliveryRateTrends(userID uint, from, to time.Time
var rows []deliveryRow
err := r.db.Table("emails").
Select("TO_CHAR(created_at, 'YYYY-MM-DD') as date, status, COUNT(*) as count").
- Where("user_id = ? AND workspace_id IS NULL AND created_at >= ? AND created_at <= ? AND status IN ?", userID, from, to, []string{"sent", "failed"}).
+ Where("user_id = ? AND workspace_id IS NULL AND created_at >= ? AND created_at <= ? AND status IN ?", userID, from, to, []string{string(models.EmailStatusSent), string(models.EmailStatusFailed)}).
Group("date, status").Order("date ASC").
Find(&rows).Error
if err != nil {
@@ -145,7 +146,7 @@ func (r *AnalyticsRepository) AdminDeliveryRateTrends(from, to time.Time) ([]Del
var rows []deliveryRow
err := r.db.Table("emails").
Select("TO_CHAR(created_at, 'YYYY-MM-DD') as date, status, COUNT(*) as count").
- Where("created_at >= ? AND created_at <= ? AND status IN ?", from, to, []string{"sent", "failed"}).
+ Where("created_at >= ? AND created_at <= ? AND status IN ?", from, to, []string{string(models.EmailStatusSent), string(models.EmailStatusFailed)}).
Group("date, status").Order("date ASC").
Find(&rows).Error
if err != nil {
@@ -169,9 +170,9 @@ func buildDeliveryRatePoints(rows []deliveryRow, from, to time.Time) []DeliveryR
m[r.Date] = p
}
switch r.Status {
- case "sent":
+ case string(models.EmailStatusSent):
p.Sent = r.Count
- case "failed":
+ case string(models.EmailStatusFailed):
p.Failed = r.Count
}
}
@@ -307,7 +308,7 @@ func (r *AnalyticsRepository) WorkspaceDeliveryRateTrends(workspaceID uint, from
var rows []deliveryRow
err := r.db.Table("emails").
Select("TO_CHAR(created_at, 'YYYY-MM-DD') as date, status, COUNT(*) as count").
- Where("workspace_id = ? AND created_at >= ? AND created_at <= ? AND status IN ?", workspaceID, from, to, []string{"sent", "failed"}).
+ Where("workspace_id = ? AND created_at >= ? AND created_at <= ? AND status IN ?", workspaceID, from, to, []string{string(models.EmailStatusSent), string(models.EmailStatusFailed)}).
Group("date, status").Order("date ASC").
Find(&rows).Error
if err != nil {