@@ -61,18 +61,19 @@ package unfurlist
61
61
62
62
import (
63
63
"bytes"
64
+ "cmp"
64
65
"compress/zlib"
65
66
"context"
66
67
"crypto/sha1"
67
68
_ "embed"
69
+ "encoding/hex"
68
70
"encoding/json"
69
71
"errors"
70
- "fmt"
71
72
"io"
72
73
"log"
73
74
"net/http"
74
75
"net/url"
75
- "sort "
76
+ "slices "
76
77
"strings"
77
78
"time"
78
79
@@ -173,12 +174,6 @@ func (u *unfurlResult) Merge(u2 *unfurlResult) {
173
174
}
174
175
}
175
176
176
- type unfurlResults []* unfurlResult
177
-
178
- func (rs unfurlResults ) Len () int { return len (rs ) }
179
- func (rs unfurlResults ) Less (i , j int ) bool { return rs [i ].idx < rs [j ].idx }
180
- func (rs unfurlResults ) Swap (i , j int ) { rs [i ], rs [j ] = rs [j ], rs [i ] }
181
-
182
177
// ConfFunc is used to configure new unfurl handler; such functions should be
183
178
// used as arguments to New function
184
179
type ConfFunc func (* unfurlHandler ) * unfurlHandler
@@ -241,7 +236,7 @@ func (h *unfurlHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
241
236
}
242
237
243
238
jobResults := make (chan * unfurlResult , 1 )
244
- results := make (unfurlResults , 0 , len (urls ))
239
+ results := make ([] * unfurlResult , 0 , len (urls ))
245
240
ctx := r .Context ()
246
241
247
242
for i , r := range urls {
@@ -252,7 +247,7 @@ func (h *unfurlHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
252
247
}
253
248
}(ctx , i , r , jobResults )
254
249
}
255
- for i := 0 ; i < len ( urls ); i ++ {
250
+ for range urls {
256
251
select {
257
252
case <- ctx .Done ():
258
253
return
@@ -261,7 +256,7 @@ func (h *unfurlHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
261
256
}
262
257
}
263
258
264
- sort . Sort (results )
259
+ slices . SortFunc (results , func ( a , b * unfurlResult ) int { return cmp . Compare ( a . idx , b . idx ) } )
265
260
for _ , r := range results {
266
261
r .normalize ()
267
262
}
@@ -535,7 +530,8 @@ probeDefaultIcon:
535
530
// mcKey returns string of hex representation of sha1 sum of string provided.
536
531
// Used to get safe keys to use with memcached
537
532
func mcKey (s string ) string {
538
- return fmt .Sprintf ("%x" , sha1 .Sum ([]byte (s )))
533
+ sum := sha1 .Sum ([]byte (s ))
534
+ return hex .EncodeToString (sum [:])
539
535
}
540
536
541
537
func blocklisted (blocklilst []string , title string ) bool {
0 commit comments