Skip to content

Commit 4a870c7

Browse files
committedJan 5, 2025
chore: run formatter
1 parent 718d14c commit 4a870c7

File tree

4 files changed

+79
-79
lines changed

4 files changed

+79
-79
lines changed
 

‎cmd/mentionee/main.go

+48-48
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88
// Configuration is read from a .env file (or just the OS env vars directly).
99
// An .env file must be present in either the process working directory
1010
// `$PWD/.env`, or in `/etc/webmention/mentionee.env`.
11-
//
11+
//
1212
// Configurable values are:
1313
// - SHUTDOWN_TIMEOUT=Seconds: How long to wait for a clean shutdown after SIGINT or SIGTERM (default 120)
1414
// - ENDPOINT=URL Path: On which path to listen for Webmentions (default /api/webmention)
1515
// - LISTEN_ADDR=Domain with Port: Bind listener to this domain:port (default :8080)
1616
// - ACCEPT_DOMAIN=Domain: Accept mentions if they point to this domain (e.g., the domain of your blog, required, no default)
1717
// - NOTIFY_BY_MAIL=external, internal or no: Whether or not to enable notifications by mail (default no)
18-
// external: use an external (relay) SMTP server
19-
// internal: use builtin SMTP (deliver mail directly to the recipient)
18+
//
2019
// Options for external SMTP server:
2120
// - MAIL_HOST=Domain: Domain of the outgoing mail server (no default, required)
2221
// - MAIL_PORT=Port: Port of the outgoing mail server (no default, required)
2322
// - MAIL_USER=Username: User to authenticate to the outgoing mail server (no default, required)
2423
// - MAIL_PASS=Password: Password to authenticate to the outgoing mail server (no default, required)
2524
// - MAIL_FROM=E-Mail address: Address used in the FROM header (default same as MAIL_USER)
2625
// - MAIL_TO=E-Mail address: Address used in the TO header (default same as MAIL_FROM, or MAIL_USER if MAIL_FROM not set)
26+
//
2727
// Options for internal SMPT server:
2828
// - MAIL_FROM=E-Mail address: Send emails from this address (required)
2929
// - MAIL_TO=E-Mail address: Send emails to this email address (required)
@@ -41,6 +41,9 @@ package main
4141

4242
import (
4343
"context"
44+
"crypto/rsa"
45+
"crypto/x509"
46+
"encoding/pem"
4447
"errors"
4548
"fmt"
4649
"log/slog"
@@ -50,14 +53,11 @@ import (
5053
"os/signal"
5154
"syscall"
5255
"time"
53-
"crypto/x509"
54-
"crypto/rsa"
55-
"encoding/pem"
5656

57-
"gopkg.in/gomail.v2"
58-
"github.com/joho/godotenv"
59-
"github.com/emersion/go-msgauth/dkim"
6057
"github.com/cvanloo/parsenv"
58+
"github.com/emersion/go-msgauth/dkim"
59+
"github.com/joho/godotenv"
60+
"gopkg.in/gomail.v2"
6161

6262
webmention "github.com/cvanloo/gowebmention"
6363
"github.com/cvanloo/gowebmention/listener"
@@ -88,34 +88,34 @@ var ConfigMailExternal struct {
8888
// For this, it needs to be authorized to send emails from the MAIL_FROM_ADDR
8989
// domain. The following DNS entries are required:
9090
//
91-
// - A | mail.example.com | 11.22.33.44
92-
// - MX | example.com | mail.example.com
93-
// - TXT | example.com | v=spf1 mx -all
94-
// - TXT | _dmarc.example.com | v=DMARC1; p=quarantine;
91+
// - A | mail.example.com | 11.22.33.44
92+
// - MX | example.com | mail.example.com
93+
// - TXT | example.com | v=spf1 mx -all
94+
// - TXT | _dmarc.example.com | v=DMARC1; p=quarantine;
9595
//
9696
// Replace example.com with your own domain, and 11.22.33.44 with the IP of the
9797
// server on which mentionee runs.
9898
//
9999
// For DKIM refer to the documentation on ConfigMailDkim.
100100
var ConfigMailInternal struct {
101-
MailFrom string `cfg:"required"`
102-
MailTo string `cfg:"required"`
103-
MailFromAddr string `cfg:"required"`
104-
MailToAddr string `cfg:"required"`
105-
MailDkimPriv string
101+
MailFrom string `cfg:"required"`
102+
MailTo string `cfg:"required"`
103+
MailFromAddr string `cfg:"required"`
104+
MailToAddr string `cfg:"required"`
105+
MailDkimPriv string
106106
}
107107

108108
// In addition to the DNS entries explained in ConfigMailInternal, you'll have
109109
// to setup another DNS entry for DKIM verification to work.
110110
//
111-
// - TXT | default._domainkey.example.com | v=DKIM1; k=rsa; p=YOUR_PUBLIC_KEY_HERE
111+
// - TXT | default._domainkey.example.com | v=DKIM1; k=rsa; p=YOUR_PUBLIC_KEY_HERE
112112
//
113113
// "default" must be the same as in MAIL_DKIM_SELECTOR.
114114
// You can create a pub/priv key pair using the commands:
115115
//
116-
// openssl genrsa -out private 1024
117-
// openssl rsa -in private -pubout -out public
118-
// sed '1d;$d' public | tr -d '\n' > spublic; echo "" >> spublic
116+
// openssl genrsa -out private 1024
117+
// openssl rsa -in private -pubout -out public
118+
// sed '1d;$d' public | tr -d '\n' > spublic; echo "" >> spublic
119119
//
120120
// MAIL_DKIM_PRIV must point to the 'private' file.
121121
// As YOUR_PUBLIC_KEY_HERE in the above DNS entry, you must use the contents
@@ -126,19 +126,19 @@ var ConfigMailInternal struct {
126126
// Since mentionee can only send, not receive emails, you might want to setup
127127
// 'rua' and 'ruf' to point to a different email address:
128128
//
129-
// - TXT | _dmarc.example.com | v=DMARC1; p=quarantine; rua=mailto:dmarc@whatever.else; ruf=mailto:dmarc-forensics@whatever.else;
129+
// - TXT | _dmarc.example.com | v=DMARC1; p=quarantine; rua=mailto:dmarc@whatever.else; ruf=mailto:dmarc-forensics@whatever.else;
130130
//
131131
// For this to work, you also need an entry on the whatever.else domain:
132132
//
133-
// - TXT | example.com._report._dmarc | v=DMARC1
133+
// - TXT | example.com._report._dmarc | v=DMARC1
134134
var ConfigMailDkim struct {
135135
MailDkimSelector string `cfg:"default=default"`
136136
MailDkimHost string `cfg:"required"`
137137
}
138138

139139
const (
140-
ExitSuccess = 0
141-
ExitFailure = 1
140+
ExitSuccess = 0
141+
ExitFailure = 1
142142
ExitConfigError = -1
143143
)
144144

@@ -174,15 +174,15 @@ func loadConfig() (opts []webmention.ReceiverOption, listenAddr, endpoint string
174174
}
175175
mailer := listener.ExternalMailer{
176176
SubjectLine: listener.DefaultSubjectLine,
177-
Body: listener.DefaultBody,
178-
From: from,
179-
To: to,
180-
Dialer: dialer,
177+
Body: listener.DefaultBody,
178+
From: from,
179+
To: to,
180+
Dialer: dialer,
181181
}
182182
aggregator := &listener.ReportAggregator{
183-
SendAfterTime: 12*time.Hour,
183+
SendAfterTime: 12 * time.Hour,
184184
SendAfterCount: -1,
185-
Sender: mailer,
185+
Sender: mailer,
186186
}
187187
opts = append(opts, webmention.WithNotifier(listener.Mailer{aggregator}))
188188
agg = aggregator
@@ -213,38 +213,38 @@ func loadConfig() (opts []webmention.ReceiverOption, listenAddr, endpoint string
213213
mailer := listener.InternalDKIMMailer{
214214
InternalMailer: listener.InternalMailer{
215215
SubjectLine: listener.DefaultSubjectLine,
216-
Body: listener.DefaultBody,
217-
FromAddr: ConfigMailInternal.MailFromAddr,
218-
ToAddr: ConfigMailInternal.MailToAddr,
219-
From: ConfigMailInternal.MailFrom,
220-
To: ConfigMailInternal.MailTo,
216+
Body: listener.DefaultBody,
217+
FromAddr: ConfigMailInternal.MailFromAddr,
218+
ToAddr: ConfigMailInternal.MailToAddr,
219+
From: ConfigMailInternal.MailFrom,
220+
To: ConfigMailInternal.MailTo,
221221
},
222222
DkimSignOpts: &dkim.SignOptions{
223-
Domain: ConfigMailDkim.MailDkimHost,
223+
Domain: ConfigMailDkim.MailDkimHost,
224224
Selector: ConfigMailDkim.MailDkimSelector,
225-
Signer: pk,
225+
Signer: pk,
226226
},
227227
}
228228
aggregator := &listener.ReportAggregator{
229-
SendAfterTime: 12*time.Hour,
229+
SendAfterTime: 12 * time.Hour,
230230
SendAfterCount: -1,
231-
Sender: mailer,
231+
Sender: mailer,
232232
}
233233
opts = append(opts, webmention.WithNotifier(listener.Mailer{aggregator}))
234234
agg = aggregator
235235
} else {
236236
mailer := listener.InternalMailer{
237237
SubjectLine: listener.DefaultSubjectLine,
238-
Body: listener.DefaultBody,
239-
FromAddr: ConfigMailInternal.MailFromAddr,
240-
ToAddr: ConfigMailInternal.MailToAddr,
241-
From: ConfigMailInternal.MailFrom,
242-
To: ConfigMailInternal.MailTo,
238+
Body: listener.DefaultBody,
239+
FromAddr: ConfigMailInternal.MailFromAddr,
240+
ToAddr: ConfigMailInternal.MailToAddr,
241+
From: ConfigMailInternal.MailFrom,
242+
To: ConfigMailInternal.MailTo,
243243
}
244244
aggregator := &listener.ReportAggregator{
245-
SendAfterTime: 12*time.Hour,
245+
SendAfterTime: 12 * time.Hour,
246246
SendAfterCount: -1,
247-
Sender: mailer,
247+
Sender: mailer,
248248
}
249249
opts = append(opts, webmention.WithNotifier(listener.Mailer{aggregator}))
250250
agg = aggregator

‎listener/mail.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package listener
22

33
import (
4+
"bytes"
45
"fmt"
56
"gopkg.in/gomail.v2"
67
"log/slog"
7-
"bytes"
88
"net/smtp"
9+
"strings"
910
"sync"
1011
"time"
11-
"strings"
1212

1313
"github.com/emersion/go-msgauth/dkim"
1414

@@ -38,7 +38,7 @@ type (
3838
}
3939
InternalDKIMMailer struct {
4040
InternalMailer
41-
DkimSignOpts *dkim.SignOptions
41+
DkimSignOpts *dkim.SignOptions
4242
}
4343
ExternalMailer struct {
4444
SubjectLine func([]webmention.Mention) string

‎receiver.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package webmention
22

33
import (
4-
"fmt"
54
"context"
5+
"fmt"
66
"golang.org/x/net/html"
77
"io"
88
"log/slog"
9+
mimelib "mime"
910
"net/http"
1011
"net/url"
11-
"strings"
12-
"strconv"
1312
"slices"
13+
"strconv"
14+
"strings"
1415
"time"
15-
mimelib "mime"
1616
)
1717

1818
type (
@@ -35,7 +35,7 @@ type (
3535
}
3636

3737
mediaRegister []mediaHandler
38-
mediaHandler struct {
38+
mediaHandler struct {
3939
name string
4040
handler MediaHandler
4141
qweight float64
@@ -46,13 +46,13 @@ type (
4646
// If no (exact) match is found, a status of StatusNoLink and a nil error must be returned.
4747
// If error is non-nil, it is treated as an internal error and the value of status is ignored.
4848
// On error, no listeners will be invoked.
49-
MediaHandler func(sourceData io.Reader, target URL) (Status, error)
50-
ReceiverOption func(*Receiver)
51-
Mention struct {
49+
MediaHandler func(sourceData io.Reader, target URL) (Status, error)
50+
ReceiverOption func(*Receiver)
51+
Mention struct {
5252
Source, Target URL
5353
Status Status
5454
}
55-
Status string
55+
Status string
5656
TargetAcceptsFunc func(source, target URL) bool
5757

5858
// A registered Notifier is informed of any valid webmentions.
@@ -121,9 +121,9 @@ func NewReceiver(opts ...ReceiverOption) *Receiver {
121121
targetAccepts: func(URL, URL) bool {
122122
return false
123123
},
124-
userAgent: "Webmention (github.com/cvanloo/gowebmention)",
124+
userAgent: "Webmention (github.com/cvanloo/gowebmention)",
125125
mentionCache: map[mentionCacheEntry]time.Time{},
126-
cacheTimeout: 3*time.Hour,
126+
cacheTimeout: 3 * time.Hour,
127127
}
128128
receiver.mediaHandler = mediaRegister{
129129
{name: "text/html", qweight: 1.0, handler: HtmlHandler},
@@ -182,7 +182,7 @@ func WithMediaHandler(mime string, qweight float64, handler MediaHandler) Receiv
182182
}
183183
} else {
184184
r.mediaHandler = append(r.mediaHandler, mediaHandler{
185-
name: mime,
185+
name: mime,
186186
qweight: qweight,
187187
handler: handler,
188188
})

‎receiver_test.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
package webmention_test
22

33
import (
4+
"context"
45
"errors"
5-
"strconv"
6-
"io"
76
"fmt"
8-
"net/url"
9-
"testing"
7+
webmention "github.com/cvanloo/gowebmention"
8+
"io"
9+
"log"
1010
"net/http"
1111
"net/http/httptest"
12+
"net/url"
13+
"strconv"
1214
"sync"
13-
"log"
14-
"context"
15+
"testing"
1516
"time"
16-
webmention "github.com/cvanloo/gowebmention"
1717
)
1818

1919
func ExampleReceiver() {
20-
acceptForTargetUrl := must(url.Parse("https://example.com"))
20+
acceptForTargetUrl := must(url.Parse("https://example.com"))
2121
webmentionee := webmention.NewReceiver(
2222
webmention.WithAcceptsFunc(func(source, target *url.URL) bool {
2323
return acceptForTargetUrl.Scheme == target.Scheme && acceptForTargetUrl.Host == target.Host
@@ -29,7 +29,7 @@ func ExampleReceiver() {
2929
mux := &http.ServeMux{}
3030
mux.Handle("/api/webmention", webmentionee)
3131
srv := http.Server{
32-
Addr: ":8080",
32+
Addr: ":8080",
3333
Handler: mux,
3434
}
3535

@@ -63,11 +63,11 @@ func accepts(source, target *url.URL) bool {
6363
}
6464

6565
type TestCase struct {
66-
Comment string
67-
SourceHandler func(ts **httptest.Server) func(w http.ResponseWriter, r *http.Request)
68-
ExpectedHttpStatus int
66+
Comment string
67+
SourceHandler func(ts **httptest.Server) func(w http.ResponseWriter, r *http.Request)
68+
ExpectedHttpStatus int
6969
ExpectedMentionStatus webmention.Status
70-
ExpectedError error
70+
ExpectedError error
7171
}
7272

7373
var TestCases = []TestCase{
@@ -79,7 +79,7 @@ var TestCases = []TestCase{
7979
w.Write([]byte(body))
8080
}
8181
},
82-
ExpectedHttpStatus: 202,
82+
ExpectedHttpStatus: 202,
8383
ExpectedMentionStatus: webmention.StatusLink,
8484
},
8585
{
@@ -89,7 +89,7 @@ var TestCases = []TestCase{
8989
w.Write([]byte("<p>I'm not linking to anything. ;-(</p>"))
9090
}
9191
},
92-
ExpectedHttpStatus: 202, // this type of validation happens async
92+
ExpectedHttpStatus: 202, // this type of validation happens async
9393
ExpectedMentionStatus: webmention.StatusNoLink,
9494
},
9595
{
@@ -100,7 +100,7 @@ var TestCases = []TestCase{
100100
w.Write([]byte(`<p>This post was deleted</p>`))
101101
}
102102
},
103-
ExpectedHttpStatus: 202,
103+
ExpectedHttpStatus: 202,
104104
ExpectedMentionStatus: webmention.StatusDeleted,
105105
},
106106
{

0 commit comments

Comments
 (0)
Please sign in to comment.