Skip to content

Commit a4403e4

Browse files
author
Anthony Wang
committed
Move httpsig algs constant slice to modules/setting/federation.go
1 parent e60158c commit a4403e4

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

modules/activitypub/client.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,6 @@ type Client struct {
5555
pubID string
5656
}
5757

58-
var algos []httpsig.Algorithm
59-
60-
func init() {
61-
algos = make([]httpsig.Algorithm, len(setting.Federation.Algorithms))
62-
for i, algo := range setting.Federation.Algorithms {
63-
algos[i] = httpsig.Algorithm(algo)
64-
}
65-
}
66-
6758
// NewClient function
6859
func NewClient(user *user_model.User, pubID string) (c *Client, err error) {
6960
if err = containsRequiredHTTPHeaders(http.MethodGet, setting.Federation.GetHeaders); err != nil {
@@ -88,7 +79,7 @@ func NewClient(user *user_model.User, pubID string) (c *Client, err error) {
8879
Proxy: proxy.Proxy(),
8980
},
9081
},
91-
algs: algos,
82+
algs: setting.HttpsigAlgs,
9283
digestAlg: httpsig.DigestAlgorithm(setting.Federation.DigestAlgorithm),
9384
getHeaders: setting.Federation.GetHeaders,
9485
postHeaders: setting.Federation.PostHeaders,

modules/setting/federation.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,19 @@ var (
2929
}
3030
)
3131

32+
// Constant slice of httpsig algorithm objects
33+
var HttpsigAlgs []httpsig.Algorithm
34+
3235
func newFederationService() {
3336
if err := Cfg.Section("federation").MapTo(&Federation); err != nil {
3437
log.Fatal("Failed to map Federation settings: %v", err)
3538
} else if !httpsig.IsSupportedDigestAlgorithm(Federation.DigestAlgorithm) {
3639
log.Fatal("unsupported digest algorithm: %s", Federation.DigestAlgorithm)
3740
return
3841
}
42+
43+
HttpsigAlgs = make([]httpsig.Algorithm, len(Federation.Algorithms))
44+
for i, alg := range Federation.Algorithms {
45+
HttpsigAlgs[i] = httpsig.Algorithm(alg)
46+
}
3947
}

0 commit comments

Comments
 (0)