/
handlers.go
36 lines (29 loc) · 916 Bytes
/
handlers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"fmt"
"net/http"
"strings"
)
func (dirs *index) ServeMux() *http.ServeMux {
mux := http.NewServeMux()
mux.Handle("/imports/", http.StripPrefix("/imports/", dirs.ImportsHandler()))
mux.Handle("/dirs/", http.StripPrefix("/dirs/", dirs.DirsHandler()))
mux.Handle("/update", dirs.UpdateHandler())
mux.Handle("/", http.StripPrefix("/", dirs.DirsHandler()))
return mux
}
func (dirs *index) DirsHandler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, strings.Join(dirs.QueryIndex(r.URL.Path, kindDirs), "\n"))
}
}
func (dirs *index) ImportsHandler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, strings.Join(dirs.QueryIndex(r.URL.Path, kindImports), "\n"))
}
}
func (dirs *index) UpdateHandler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
dirs.Index()
}
}