support requesting subdirs of repos
This commit is contained in:
parent
76b657aa3f
commit
23af74a05e
16
main.go
16
main.go
@ -8,6 +8,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Repo struct {
|
type Repo struct {
|
||||||
@ -43,16 +44,27 @@ type Server struct {
|
|||||||
func (s *Server) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
func (s *Server) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
||||||
log.Print("request: ", req.URL.Path)
|
log.Print("request: ", req.URL.Path)
|
||||||
id := req.URL.Path[1:]
|
id := req.URL.Path[1:]
|
||||||
|
for len(id) > 0 {
|
||||||
|
log.Print(" trying id=", id)
|
||||||
if repo, ok := s.config.Repos[id]; ok {
|
if repo, ok := s.config.Repos[id]; ok {
|
||||||
err := s.template.Execute(resp, repo)
|
err := s.template.Execute(resp, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.WriteHeader(500)
|
resp.WriteHeader(500)
|
||||||
resp.Write([]byte("Internal Server Error\n\n"))
|
resp.Write([]byte("Internal Server Error\n\n"))
|
||||||
resp.Write([]byte(fmt.Sprintf("Error: Executing Template: %s, id=%s\n\nRepo=%v", err.Error(), id, repo)))
|
resp.Write([]byte(fmt.Sprintf("Error: Executing Template: %s, id=%s\n\nRepo=%v", err.Error(), id, repo)))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
} else {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
i := strings.LastIndexByte(id, '/')
|
||||||
|
if i == -1 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
id = id[:i]
|
||||||
|
}
|
||||||
|
log.Print(id, ": Error 404")
|
||||||
resp.WriteHeader(404)
|
resp.WriteHeader(404)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
Loading…
Reference in New Issue
Block a user