-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrip.go
46 lines (39 loc) · 884 Bytes
/
rip.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
37
38
39
40
41
42
43
44
45
46
package rip
import (
"net/http"
//"strings"
)
/*
type Resource struct {
Add(string, interface{}) Resource
Get(string) Resource
ServeHTTP(http.ResponseWriter, *http.Request)
}
*/
type Handler struct {
*http.ServeMux
resources map[string]interface{}
}
func New() *Handler {
return &Handler{http.NewServeMux(), make(map[string]interface{})}
}
func (h *Handler) Add(name string, resource interface{}) *Handler {
h.HandleFunc("/"+name+"/", requestHandler(resource))
return h
}
/*
func (r *Handler) Get(name string) *Handler {
return r.resources[name]
}
func (r *Handler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
name := req.URL.Path[1:]
for needle, res := range r.resources {
if needle == name || strings.HasPrefix(name, needle+"/") {
if len(name) > len(needle) {
req.URL.Path = name[len(needle):]
res.ServeHTTP(resp, req)
}
}
}
}
*/