Skip to content

Commit 8848922

Browse files
committed
Remove superfluous consts dep in init functions by separating URL consts.
1 parent e2f24a1 commit 8848922

File tree

15 files changed

+220
-200
lines changed

15 files changed

+220
-200
lines changed

cmd/admin.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ type serverConfig struct {
2626
// GetServerConfig returns general server config.
2727
func (a *App) GetServerConfig(c echo.Context) error {
2828
out := serverConfig{
29-
RootURL: a.constants.RootURL,
30-
FromEmail: a.constants.FromEmail,
31-
Lang: a.constants.Lang,
32-
Permissions: a.constants.PermissionsRaw,
33-
HasLegacyUser: a.constants.HasLegacyUser,
29+
RootURL: a.urlCfg.RootURL,
30+
FromEmail: a.cfg.FromEmail,
31+
Lang: a.cfg.Lang,
32+
Permissions: a.cfg.PermissionsRaw,
33+
HasLegacyUser: a.cfg.HasLegacyUser,
3434
}
3535

3636
// Language list.

cmd/archive.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (a *App) GetCampaignArchives(c echo.Context) error {
5353
func (a *App) GetCampaignArchivesFeed(c echo.Context) error {
5454
var (
5555
pg = a.paginator.NewFromURL(c.Request().URL.Query())
56-
showFullContent = a.constants.EnablePublicArchiveRSSContent
56+
showFullContent = a.cfg.EnablePublicArchiveRSSContent
5757
)
5858

5959
// Get archives from the DB.
@@ -81,8 +81,8 @@ func (a *App) GetCampaignArchivesFeed(c echo.Context) error {
8181

8282
// Generate the feed.
8383
feed := &feeds.Feed{
84-
Title: a.constants.SiteName,
85-
Link: &feeds.Link{Href: a.constants.RootURL},
84+
Title: a.cfg.SiteName,
85+
Link: &feeds.Link{Href: a.urlCfg.RootURL},
8686
Description: a.i18n.T("public.archiveTitle"),
8787
Items: out,
8888
}
@@ -215,9 +215,9 @@ func (a *App) getCampaignArchives(offset, limit int, renderBody bool) ([]campArc
215215

216216
// The campaign may have a custom slug.
217217
if camp.ArchiveSlug.Valid {
218-
archive.URL, _ = url.JoinPath(a.constants.ArchiveURL, camp.ArchiveSlug.String)
218+
archive.URL, _ = url.JoinPath(a.urlCfg.ArchiveURL, camp.ArchiveSlug.String)
219219
} else {
220-
archive.URL, _ = url.JoinPath(a.constants.ArchiveURL, camp.UUID)
220+
archive.URL, _ = url.JoinPath(a.urlCfg.ArchiveURL, camp.UUID)
221221
}
222222

223223
// Render the full template body if requested.

cmd/auth.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ func (a *App) renderLoginPage(c echo.Context, loginErr error) error {
190190
oidcProvider = ""
191191
oidcLogo = ""
192192
)
193-
if a.constants.Security.OIDC.Enabled {
193+
if a.cfg.Security.OIDC.Enabled {
194194
oidcLogo = "oidc.png"
195-
u, err := url.Parse(a.constants.Security.OIDC.Provider)
195+
u, err := url.Parse(a.cfg.Security.OIDC.Provider)
196196
if err == nil {
197197
h := strings.Split(u.Hostname(), ".")
198198

@@ -330,7 +330,7 @@ func (a *App) doFirstTimeSetup(c echo.Context) error {
330330
Type: auth.RoleTypeUser,
331331
Name: null.NewString("Super Admin", true),
332332
}
333-
for p := range a.constants.Permissions {
333+
for p := range a.cfg.Permissions {
334334
r.Permissions = append(r.Permissions, p)
335335
}
336336

cmd/bounce.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (a *App) BounceWebhook(c echo.Context) error {
143143
bounces = append(bounces, b)
144144

145145
// Amazon SES.
146-
case service == "ses" && a.constants.BounceSESEnabled:
146+
case service == "ses" && a.cfg.BounceSESEnabled:
147147
switch c.Request().Header.Get("X-Amz-Sns-Message-Type") {
148148
// SNS webhook registration confirmation. Only after these are processed will the endpoint
149149
// start getting bounce notifications.
@@ -167,7 +167,7 @@ func (a *App) BounceWebhook(c echo.Context) error {
167167
}
168168

169169
// SendGrid.
170-
case service == "sendgrid" && a.constants.BounceSendgridEnabled:
170+
case service == "sendgrid" && a.cfg.BounceSendgridEnabled:
171171
var (
172172
sig = c.Request().Header.Get("X-Twilio-Email-Event-Webhook-Signature")
173173
ts = c.Request().Header.Get("X-Twilio-Email-Event-Webhook-Timestamp")
@@ -182,7 +182,7 @@ func (a *App) BounceWebhook(c echo.Context) error {
182182
bounces = append(bounces, bs...)
183183

184184
// Postmark.
185-
case service == "postmark" && a.constants.BouncePostmarkEnabled:
185+
case service == "postmark" && a.cfg.BouncePostmarkEnabled:
186186
bs, err := a.bounce.Postmark.ProcessBounce(rawReq, c)
187187
if err != nil {
188188
a.log.Printf("error processing postmark notification: %v", err)
@@ -195,7 +195,7 @@ func (a *App) BounceWebhook(c echo.Context) error {
195195
bounces = append(bounces, bs...)
196196

197197
// ForwardEmail.
198-
case service == "forwardemail" && a.constants.BounceForwardemailEnabled:
198+
case service == "forwardemail" && a.cfg.BounceForwardemailEnabled:
199199
var (
200200
sig = c.Request().Header.Get("X-Webhook-Signature")
201201
)

cmd/campaigns.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ func (a *App) sendTestMessage(sub models.Subscriber, camp *models.Campaign) erro
553553
// validateCampaignFields validates incoming campaign field values.
554554
func (a *App) validateCampaignFields(c campReq) (campReq, error) {
555555
if c.FromEmail == "" {
556-
c.FromEmail = a.constants.FromEmail
556+
c.FromEmail = a.cfg.FromEmail
557557
} else if !reFromAddress.Match([]byte(c.FromEmail)) {
558558
if _, err := a.importer.SanitizeEmail(c.FromEmail); err != nil {
559559
return c, errors.New(a.i18n.T("campaigns.fieldInvalidFromEmail"))

cmd/handlers.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func initHTTPHandlers(e *echo.Echo, a *App) {
4949

5050
// On no-auth, redirect to login page
5151
if _, ok := u.(*echo.HTTPError); ok {
52-
u, _ := url.Parse(a.constants.LoginURL)
52+
u, _ := url.Parse(a.urlCfg.LoginURL)
5353
q := url.Values{}
5454
q.Set("next", c.Request().RequestURI)
5555
u.RawQuery = q.Encode()
@@ -197,7 +197,7 @@ func initHTTPHandlers(e *echo.Echo, a *App) {
197197
g.PUT("/api/roles/lists/:id", pm(a.UpdateListRole, "roles:manage"))
198198
g.DELETE("/api/roles/:id", pm(a.DeleteRole, "roles:manage"))
199199

200-
if a.constants.BounceWebhooksEnabled {
200+
if a.cfg.BounceWebhooksEnabled {
201201
// Private authenticated bounce endpoint.
202202
g.POST("/webhooks/bounce", pm(a.BounceWebhook, "webhooks:post_bounce"))
203203
}
@@ -209,7 +209,7 @@ func initHTTPHandlers(e *echo.Echo, a *App) {
209209
// Public unauthenticated endpoints.
210210
g := e.Group("")
211211

212-
if a.constants.BounceWebhooksEnabled {
212+
if a.cfg.BounceWebhooksEnabled {
213213
// Public bounce endpoints for webservices like SES.
214214
g.POST("/webhooks/service/:service", a.BounceWebhook)
215215
}
@@ -223,15 +223,15 @@ func initHTTPHandlers(e *echo.Echo, a *App) {
223223
g.GET(path.Join(uriAdmin, "/login"), a.LoginPage)
224224
g.POST(path.Join(uriAdmin, "/login"), a.LoginPage)
225225

226-
if a.constants.Security.OIDC.Enabled {
226+
if a.cfg.Security.OIDC.Enabled {
227227
g.POST("/auth/oidc", a.OIDCLogin)
228228
g.GET("/auth/oidc", a.OIDCFinish)
229229
}
230230

231231
// Public APIs.
232232
g.GET("/api/public/lists", a.GetPublicLists)
233233
g.POST("/api/public/subscription", a.PublicSubscription)
234-
if a.constants.EnablePublicArchive {
234+
if a.cfg.EnablePublicArchive {
235235
g.GET("/api/public/archive", a.GetCampaignArchives)
236236
}
237237

@@ -249,7 +249,7 @@ func initHTTPHandlers(e *echo.Echo, a *App) {
249249
g.GET("/campaign/:campUUID/:subUUID", noIndex(validateUUID(a.ViewCampaignMessage, "campUUID", "subUUID")))
250250
g.GET("/campaign/:campUUID/:subUUID/px.png", noIndex(validateUUID(a.RegisterCampaignView, "campUUID", "subUUID")))
251251

252-
if a.constants.EnablePublicArchive {
252+
if a.cfg.EnablePublicArchive {
253253
g.GET("/archive", a.CampaignArchivesPage)
254254
g.GET("/archive.xml", a.GetCampaignArchivesFeed)
255255
g.GET("/archive/:id", a.CampaignArchivePage)
@@ -283,7 +283,7 @@ func (a *App) AdminPage(c echo.Context) error {
283283
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
284284
}
285285

286-
b = bytes.ReplaceAll(b, []byte("asset_version"), []byte(a.constants.AssetVersion))
286+
b = bytes.ReplaceAll(b, []byte("asset_version"), []byte(a.cfg.AssetVersion))
287287

288288
return c.HTMLBlob(http.StatusOK, b)
289289
}
@@ -306,19 +306,19 @@ func serveCustomAppearance(name string) echo.HandlerFunc {
306306

307307
switch name {
308308
case "admin.custom_css":
309-
out = app.constants.Appearance.AdminCSS
309+
out = app.cfg.Appearance.AdminCSS
310310
hdr = "text/css; charset=utf-8"
311311

312312
case "admin.custom_js":
313-
out = app.constants.Appearance.AdminJS
313+
out = app.cfg.Appearance.AdminJS
314314
hdr = "application/javascript; charset=utf-8"
315315

316316
case "public.custom_css":
317-
out = app.constants.Appearance.PublicCSS
317+
out = app.cfg.Appearance.PublicCSS
318318
hdr = "text/css; charset=utf-8"
319319

320320
case "public.custom_js":
321-
out = app.constants.Appearance.PublicJS
321+
out = app.cfg.Appearance.PublicJS
322322
hdr = "application/javascript; charset=utf-8"
323323
}
324324

0 commit comments

Comments
 (0)