implement /random redirect
This commit is contained in:
parent
308aa11bf0
commit
9a6321fe6f
@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -95,6 +96,17 @@ func (this *WikiServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
this.serveRedirect(w, this.opts.ExpectBaseURL+`view/`+url.QueryEscape(this.opts.DefaultPage))
|
this.serveRedirect(w, this.opts.ExpectBaseURL+`view/`+url.QueryEscape(this.opts.DefaultPage))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
} else if remainingPath == "random" {
|
||||||
|
titles, err := this.db.ListTitles()
|
||||||
|
if err != nil {
|
||||||
|
this.serveInternalError(w, r, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
chosenArticle := titles[rand.Intn(len(titles))]
|
||||||
|
this.serveRedirect(w, this.opts.ExpectBaseURL+`view/`+url.QueryEscape(chosenArticle))
|
||||||
|
return
|
||||||
|
|
||||||
} else if strings.HasPrefix(remainingPath, "view/") {
|
} else if strings.HasPrefix(remainingPath, "view/") {
|
||||||
articleTitle, err := url.QueryUnescape(remainingPath[len("view/"):])
|
articleTitle, err := url.QueryUnescape(remainingPath[len("view/"):])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user