...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package server
18
19 import (
20 "bytes"
21 "fmt"
22 "math/rand"
23 "net/http"
24 "net/url"
25 "time"
26 )
27
28 func (s *Server) serveDirectory(req *http.Request) (Response, error) {
29 sibs := s.Config.Server.Siblings
30 if len(sibs) == 0 {
31 u := new(url.URL)
32 *u = *req.URL
33 if req.TLS != nil {
34 u.Scheme = "https"
35 } else {
36 u.Scheme = "http"
37 }
38 u.Host = req.Host
39 sibs = []string{u.String()}
40 }
41 var buf bytes.Buffer
42 shuf := rand.New(rand.NewSource(time.Now().UnixNano()))
43 order := shuf.Perm(len(sibs))
44 for _, i := range order {
45 fmt.Fprintf(&buf, "%s\r\n", sibs[i])
46 }
47 return StringResponse(http.StatusOK, buf.String()), nil
48 }
49
View as plain text