Move httpsig algos slice to an init() function

This commit is contained in:
Anthony Wang 2022-06-12 14:24:47 -05:00
parent 76f06cee31
commit d1f14ff2c7
No known key found for this signature in database
GPG key ID: BC96B00AEC5F2D76

View file

@ -54,6 +54,15 @@ type Client struct {
pubID string
}
var algos []httpsig.Algorithm
func init() {
algos = make([]httpsig.Algorithm, len(setting.Federation.Algorithms))
for i, algo := range setting.Federation.Algorithms {
algos[i] = httpsig.Algorithm(algo)
}
}
// NewClient function
func NewClient(user *user_model.User, pubID string) (c *Client, err error) {
if err = containsRequiredHTTPHeaders(http.MethodGet, setting.Federation.GetHeaders); err != nil {
@ -61,10 +70,6 @@ func NewClient(user *user_model.User, pubID string) (c *Client, err error) {
} else if err = containsRequiredHTTPHeaders(http.MethodPost, setting.Federation.PostHeaders); err != nil {
return
}
algos := make([]httpsig.Algorithm, len(setting.Federation.Algorithms))
for i, algo := range setting.Federation.Algorithms {
algos[i] = httpsig.Algorithm(algo)
}
priv, err := GetPrivateKey(user)
if err != nil {