router: scaffolding for remaining routes
This commit is contained in:
parent
06a07af36d
commit
ca39609fef
@ -2,6 +2,7 @@ package archive
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -13,6 +14,8 @@ type ArchiveServer struct {
|
||||
timezone *time.Location
|
||||
cfg *Config
|
||||
startup time.Time
|
||||
|
||||
rxViewRoot, rxViewPage, rxSearch, rxSearchRx *regexp.Regexp
|
||||
}
|
||||
|
||||
func NewArchiveServer(cfg *Config) (*ArchiveServer, error) {
|
||||
@ -36,8 +39,12 @@ func NewArchiveServer(cfg *Config) (*ArchiveServer, error) {
|
||||
}
|
||||
|
||||
return &ArchiveServer{
|
||||
timezone: tz,
|
||||
cfg: cfg,
|
||||
startup: time.Now(),
|
||||
timezone: tz,
|
||||
cfg: cfg,
|
||||
startup: time.Now(),
|
||||
rxViewRoot: regexp.MustCompile(`^/([^/]+)/(\d+)/(\d+)$`),
|
||||
rxViewPage: regexp.MustCompile(`^/([^/]+)/(\d+)/(\d+)/(?:page-)?(\d+)$`),
|
||||
rxSearch: regexp.MustCompile(`^/([^/]+)/search/(.*)$`),
|
||||
rxSearchRx: regexp.MustCompile(`^/([^/]+)/rx/(.*)$`),
|
||||
}, nil
|
||||
}
|
||||
|
23
Router.go
23
Router.go
@ -80,9 +80,30 @@ func (this *ArchiveServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
arc := NewArchiveState(this)
|
||||
|
||||
if len(r.URL.Query().Get("y")) > 0 || len(r.URL.Query().Get("q")) > 0 || len(r.URL.Query().Get("h")) > 0 {
|
||||
if r.URL.Path == `/` {
|
||||
ls := &this.cfg.Logs[0]
|
||||
slug, _ := this.bestSlugFor(ls)
|
||||
dt := ls.LatestDate()
|
||||
http.Redirect(w, r, fmt.Sprintf(`/%s/%d/%d`, slug, dt.Year, dt.Month), http.StatusTemporaryRedirect)
|
||||
|
||||
} else if len(r.URL.Query().Get("y")) > 0 || len(r.URL.Query().Get("q")) > 0 || len(r.URL.Query().Get("h")) > 0 {
|
||||
this.legacyRoute(w, r)
|
||||
|
||||
} else if r.URL.Path == `/download` {
|
||||
arc.renderError(w, "Not implemented.") // FIXME
|
||||
|
||||
} else if this.rxViewRoot.MatchString(r.URL.Path) {
|
||||
arc.renderError(w, "Not implemented.") // FIXME
|
||||
|
||||
} else if this.rxViewPage.MatchString(r.URL.Path) {
|
||||
arc.renderError(w, "Not implemented.") // FIXME
|
||||
|
||||
} else if this.rxSearch.MatchString(r.URL.Path) {
|
||||
arc.renderError(w, "Not implemented.") // FIXME
|
||||
|
||||
} else if this.rxSearchRx.MatchString(r.URL.Path) {
|
||||
arc.renderError(w, "Not implemented.") // FIXME
|
||||
|
||||
} else {
|
||||
arc.renderError(w, "Unknown route.")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user