| 1 | package auxserverscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src go1.13 bytes/" |
| 5 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.13 `encoding/json`/" |
| 6 | "fmtscip-go gomod github.com/golang/go/src go1.13 fmt/" |
| 7 | "html/templatescip-go gomod github.com/golang/go/src go1.13 `html/template`/" |
| 8 | "ioscip-go gomod github.com/golang/go/src go1.13 io/" |
| 9 | "net/httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/" |
| 10 | "net/urlscip-go gomod github.com/golang/go/src go1.13 `net/url`/" |
| 11 | "sortscip-go gomod github.com/golang/go/src go1.13 sort/" |
| 12 | "stringsscip-go gomod github.com/golang/go/src go1.13 strings/" |
| 13 | "syncscip-go gomod github.com/golang/go/src go1.13 sync/" |
| 14 | |
| 15 | "github.com/Debian/debiman/internal/commontmplscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/commontmpl`/" |
| 16 | "github.com/Debian/debiman/internal/manpagescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/" |
| 17 | "github.com/Debian/debiman/internal/redirectscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/redirect`/" |
| 18 | ) |
| 19 | |
| 20 | type Serverscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server# struct { |
| 21 | idxscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#idx. redirectscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/redirect`/.Indexscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/redirect`/Index# |
| 22 | idxMuscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#idxMu. syncscip-go gomod github.com/golang/go/src go1.13 sync/.RWMutexscip-go gomod github.com/golang/go/src go1.13 sync/RWMutex# |
| 23 | notFoundTmplscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#notFoundTmpl. *templatescip-go gomod github.com/golang/go/src go1.13 `html/template`/.Templatescip-go gomod github.com/golang/go/src go1.13 `html/template`/Template# |
| 24 | debimanVersionscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#debimanVersion. string |
| 25 | sortedNamesscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#sortedNames. []string |
| 26 | } |
| 27 | |
| 28 | func NewServerscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/NewServer().(idx redirectscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/redirect`/.Indexscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/redirect`/Index#, notFoundTmpl *templatescip-go gomod github.com/golang/go/src go1.13 `html/template`/.Templatescip-go gomod github.com/golang/go/src go1.13 `html/template`/Template#, debimanVersion string) *Serverscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server# { |
| 29 | s := &Serverscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#{ |
| 30 | idxscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#idx.: idx, |
| 31 | notFoundTmplscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#notFoundTmpl.: notFoundTmpl, |
| 32 | debimanVersionscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#debimanVersion.: debimanVersion, |
| 33 | } |
| 34 | s.prepareSuggestscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#prepareSuggest().() |
| 35 | return s |
| 36 | } |
| 37 | |
| 38 | // prepareSuggest sets sortedNames to a sorted slice of |
| 39 | // <name>.<section> strings found in idx. |
| 40 | func (s *Serverscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#) prepareSuggestscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#prepareSuggest().() { |
| 41 | names := make(map[string]bool) |
| 42 | for name, entries := range s.idxscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#idx..Entriesscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/redirect`/Index#Entries. { |
| 43 | for _, entry := range entries { |
| 44 | names[name+"."+entry.Sectionscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/redirect`/IndexEntry#Section.] = true |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | result := make([]string, 0, len(names)) |
| 49 | for name := range names { |
| 50 | result = append(result, name) |
| 51 | } |
| 52 | sortscip-go gomod github.com/golang/go/src go1.13 sort/.Stringsscip-go gomod github.com/golang/go/src go1.13 sort/Strings().(result) |
| 53 | s.sortedNamesscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#sortedNames. = result |
| 54 | } |
| 55 | |
| 56 | func (s *Serverscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#) SwapIndexscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#SwapIndex().(idx redirectscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/redirect`/.Indexscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/redirect`/Index#) error { |
| 57 | u, err := urlscip-go gomod github.com/golang/go/src go1.13 `net/url`/.Parsescip-go gomod github.com/golang/go/src go1.13 `net/url`/Parse().("/i3") |
| 58 | if err != nil { |
| 59 | return err |
| 60 | } |
| 61 | redir, err := idx.Redirectscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/redirect`/Index#Redirect().(&httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.13 `net/http`/Request#{ |
| 62 | URLscip-go gomod github.com/golang/go/src go1.13 `net/http`/Request#URL.: u, |
| 63 | }) |
| 64 | if err != nil { |
| 65 | return fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("idx.Redirect: %v", err) |
| 66 | } |
| 67 | if !stringsscip-go gomod github.com/golang/go/src go1.13 strings/.HasSuffixscip-go gomod github.com/golang/go/src go1.13 strings/HasSuffix().(redir, "i3.1.en.html") { |
| 68 | return fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Redirect(/i3) does not lead to i3.1.en.html: got %q", redir) |
| 69 | } |
| 70 | s.idxMuscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#idxMu..Lockscip-go gomod github.com/golang/go/src go1.13 sync/RWMutex#Lock().() |
| 71 | defer s.idxMuscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#idxMu..Unlockscip-go gomod github.com/golang/go/src go1.13 sync/RWMutex#Unlock().() |
| 72 | s.idxscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#idx. = idx |
| 73 | s.prepareSuggestscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#prepareSuggest().() |
| 74 | return nil |
| 75 | } |
| 76 | |
| 77 | func (s *Serverscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#) redirectscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#redirect().(r *httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.13 `net/http`/Request#) (string, error) { |
| 78 | s.idxMuscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#idxMu..RLockscip-go gomod github.com/golang/go/src go1.13 sync/RWMutex#RLock().() |
| 79 | defer s.idxMuscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#idxMu..RUnlockscip-go gomod github.com/golang/go/src go1.13 sync/RWMutex#RUnlock().() |
| 80 | return s.idxscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#idx..Redirectscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/redirect`/Index#Redirect().(r) |
| 81 | } |
| 82 | |
| 83 | func (s *Serverscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#) HandleRedirectscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#HandleRedirect().(w httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.13 `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.13 `net/http`/Request#) { |
| 84 | redir, err := s.redirectscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#redirect().(r) |
| 85 | if err != nil { |
| 86 | if nf, ok := err.(*redirectscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/redirect`/.NotFoundErrorscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/redirect`/NotFoundError#); ok { |
| 87 | var buf bytesscip-go gomod github.com/golang/go/src go1.13 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.13 bytes/Buffer# |
| 88 | err = s.notFoundTmplscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#notFoundTmpl..Executescip-go gomod github.com/golang/go/src go1.13 `html/template`/Template#Execute().(&buf, struct { |
| 89 | Title string |
| 90 | DebimanVersion string |
| 91 | Breadcrumbs []string // incorrect type, but empty anyway |
| 92 | FooterExtra string |
| 93 | Manpage string |
| 94 | BestChoice redirectscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/redirect`/.IndexEntryscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/redirect`/IndexEntry# |
| 95 | Meta *manpagescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/.Metascip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta# |
| 96 | HrefLangs []*manpagescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/.Metascip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta# |
| 97 | }{ |
| 98 | Title: "Not Found", |
| 99 | DebimanVersion: s.debimanVersionscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#debimanVersion., |
| 100 | Manpage: nf.Manpagescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/redirect`/NotFoundError#Manpage., |
| 101 | BestChoice: nf.BestChoicescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/redirect`/NotFoundError#BestChoice., |
| 102 | }) |
| 103 | if err == nil { |
| 104 | w.Headerscip-go gomod github.com/golang/go/src go1.13 `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src go1.13 `net/http`/Header#Set().("Content-Type", "text/html; charset=utf-8") |
| 105 | w.Headerscip-go gomod github.com/golang/go/src go1.13 `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src go1.13 `net/http`/Header#Set().("X-Content-Type-Options", "nosniff") |
| 106 | w.WriteHeaderscip-go gomod github.com/golang/go/src go1.13 `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.StatusNotFoundscip-go gomod github.com/golang/go/src go1.13 `net/http`/StatusNotFound.) |
| 107 | ioscip-go gomod github.com/golang/go/src go1.13 io/.Copyscip-go gomod github.com/golang/go/src go1.13 io/Copy().(w, &buf) |
| 108 | return |
| 109 | } |
| 110 | /* fallthrough */ |
| 111 | } |
| 112 | httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.13 `net/http`/Error().(w, err.Error(), httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.StatusInternalServerErrorscip-go gomod github.com/golang/go/src go1.13 `net/http`/StatusInternalServerError.) |
| 113 | return |
| 114 | } |
| 115 | |
| 116 | // StatusTemporaryRedirect (HTTP 307) means subsequent requests |
| 117 | // should use the old URI, which is what we want — the redirect |
| 118 | // target will likely change in the future. |
| 119 | httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.Redirectscip-go gomod github.com/golang/go/src go1.13 `net/http`/Redirect().(w, r, commontmplscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/commontmpl`/.BaseURLPathscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/commontmpl`/BaseURLPath().()+redir, httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.StatusTemporaryRedirectscip-go gomod github.com/golang/go/src go1.13 `net/http`/StatusTemporaryRedirect.) |
| 120 | } |
| 121 | |
| 122 | func (s *Serverscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#) HandleJumpscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#HandleJump().(w httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.13 `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.13 `net/http`/Request#) { |
| 123 | q := r.FormValuescip-go gomod github.com/golang/go/src go1.13 `net/http`/Request#FormValue().("q") |
| 124 | if stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.13 strings/TrimSpace().(q) == "" { |
| 125 | httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.13 `net/http`/Error().(w, "No q= query parameter specified", httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src go1.13 `net/http`/StatusBadRequest.) |
| 126 | return |
| 127 | } |
| 128 | |
| 129 | r.URLscip-go gomod github.com/golang/go/src go1.13 `net/http`/Request#URL..Pathscip-go gomod github.com/golang/go/src go1.13 `net/url`/URL#Path. = "/" + stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.13 strings/TrimPrefix().(q, commontmplscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/commontmpl`/.BaseURLPathscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/commontmpl`/BaseURLPath().()) |
| 130 | s.HandleRedirectscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#HandleRedirect().(w, r) |
| 131 | } |
| 132 | |
| 133 | func (s *Serverscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#) suggestscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#suggest().(q string) []string { |
| 134 | s.idxMuscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#idxMu..RLockscip-go gomod github.com/golang/go/src go1.13 sync/RWMutex#RLock().() |
| 135 | defer s.idxMuscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#idxMu..RUnlockscip-go gomod github.com/golang/go/src go1.13 sync/RWMutex#RUnlock().() |
| 136 | |
| 137 | i := sortscip-go gomod github.com/golang/go/src go1.13 sort/.Searchscip-go gomod github.com/golang/go/src go1.13 sort/Search().(len(s.sortedNamesscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#sortedNames.), func(i int) bool { |
| 138 | return s.sortedNamesscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#sortedNames.[i] >= q |
| 139 | }) |
| 140 | |
| 141 | var result []string |
| 142 | for i < len(s.sortedNamesscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#sortedNames.) { |
| 143 | if stringsscip-go gomod github.com/golang/go/src go1.13 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.13 strings/HasPrefix().(s.sortedNamesscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#sortedNames.[i], q) { |
| 144 | result = append(result, s.sortedNamesscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#sortedNames.[i]) |
| 145 | } else { |
| 146 | break |
| 147 | } |
| 148 | i++ |
| 149 | } |
| 150 | if len(result) > 10 { |
| 151 | result = result[:10] |
| 152 | } |
| 153 | return result |
| 154 | } |
| 155 | |
| 156 | func (s *Serverscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#) HandleSuggestscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#HandleSuggest().(w httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.13 `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.13 `net/http`/Request#) { |
| 157 | q := r.FormValuescip-go gomod github.com/golang/go/src go1.13 `net/http`/Request#FormValue().("q") |
| 158 | if stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.13 strings/TrimSpace().(q) == "" { |
| 159 | httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.13 `net/http`/Error().(w, "No q= query parameter specified", httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src go1.13 `net/http`/StatusBadRequest.) |
| 160 | return |
| 161 | } |
| 162 | |
| 163 | r.URLscip-go gomod github.com/golang/go/src go1.13 `net/http`/Request#URL..Pathscip-go gomod github.com/golang/go/src go1.13 `net/url`/URL#Path. = "/" + q |
| 164 | completions := s.suggestscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/auxserver`/Server#suggest().(q) |
| 165 | |
| 166 | var buf bytesscip-go gomod github.com/golang/go/src go1.13 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.13 bytes/Buffer# |
| 167 | if err := jsonscip-go gomod github.com/golang/go/src go1.13 `encoding/json`/.NewEncoderscip-go gomod github.com/golang/go/src go1.13 `encoding/json`/NewEncoder().(&buf).Encodescip-go gomod github.com/golang/go/src go1.13 `encoding/json`/Encoder#Encode().([]interface{}{ |
| 168 | q, |
| 169 | completions, |
| 170 | }); err != nil { |
| 171 | httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.13 `net/http`/Error().(w, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("encoding response: %v", err), httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.StatusInternalServerErrorscip-go gomod github.com/golang/go/src go1.13 `net/http`/StatusInternalServerError.) |
| 172 | return |
| 173 | } |
| 174 | ioscip-go gomod github.com/golang/go/src go1.13 io/.Copyscip-go gomod github.com/golang/go/src go1.13 io/Copy().(w, &buf) |
| 175 | } |