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"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Repo struct {
|
||||
@ -43,17 +44,28 @@ type Server struct {
|
||||
func (s *Server) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
||||
log.Print("request: ", req.URL.Path)
|
||||
id := req.URL.Path[1:]
|
||||
for len(id) > 0 {
|
||||
log.Print(" trying id=", id)
|
||||
if repo, ok := s.config.Repos[id]; ok {
|
||||
err := s.template.Execute(resp, repo)
|
||||
if err != nil {
|
||||
resp.WriteHeader(500)
|
||||
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)))
|
||||
return
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
i := strings.LastIndexByte(id, '/')
|
||||
if i == -1 {
|
||||
break
|
||||
}
|
||||
id = id[:i]
|
||||
}
|
||||
log.Print(id, ": Error 404")
|
||||
resp.WriteHeader(404)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
var c Config
|
||||
|
Loading…
Reference in New Issue
Block a user