forked from etcd-io/etcd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
34 lines (29 loc) · 834 Bytes
/
handler.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
package v2
import (
"net/http"
"github.com/gorilla/mux"
)
// prefix is appended to the lock's prefix since the leader mod uses the lock mod.
const prefix = "/_mod/leader"
// handler manages the leader HTTP request.
type handler struct {
*mux.Router
client *http.Client
transport *http.Transport
addr string
}
// NewHandler creates an HTTP handler that can be registered on a router.
func NewHandler(addr string) (http.Handler) {
transport := &http.Transport{DisableKeepAlives: false}
h := &handler{
Router: mux.NewRouter(),
client: &http.Client{Transport: transport},
transport: transport,
addr: addr,
}
h.StrictSlash(false)
h.HandleFunc("/{key:.*}", h.getHandler).Methods("GET")
h.HandleFunc("/{key:.*}", h.setHandler).Methods("PUT")
h.HandleFunc("/{key:.*}", h.deleteHandler).Methods("DELETE")
return h
}