summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRagnis Armus <ragnis@armus.ee>2018-07-15 16:03:02 +0300
committerRagnis Armus <ragnis@armus.ee>2018-07-15 16:03:02 +0300
commit2242b9beaffbd8570aed175e8b97bcd6197de6d6 (patch)
tree4728c0eede4e182d06717374fc303dfe05b5aa8b
parentfe98453415c06f812bb7be7a728cabfe47c2060a (diff)
handle sub-packages
-rw-r--r--main.go18
1 files changed, 16 insertions, 2 deletions
diff --git a/main.go b/main.go
index eb402d6..23e1725 100644
--- a/main.go
+++ b/main.go
@@ -33,8 +33,7 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
serveStatus(w, 404)
return
}
- handler, ok := handlers[r.URL.Path]
- if ok {
+ if handler, ok := findHandler(r.URL.Path); ok {
handler.ServeHTTP(w, r)
} else {
serveStatus(w, 404)
@@ -54,6 +53,21 @@ func createRepoHandler(cfg *cgitrc.Config, r *cgitrc.Repo) http.Handler {
})
}
+func findHandler(path string) (http.Handler, bool) {
+ path = strings.TrimSuffix(path, "/")
+ for path != "" {
+ if handler, ok := handlers[path]; ok {
+ return handler, true
+ }
+ if i := strings.LastIndexByte(path, '/'); i > 0 {
+ path = path[:i]
+ } else {
+ path = ""
+ }
+ }
+ return nil, false
+}
+
func main() {
var (
bindAddr string