use path values instead of query parameters for lookup
This commit is contained in:
parent
8047f4f13e
commit
4b44ffcd13
@ -27,8 +27,7 @@ func (cl *Client) Find(ctx context.Context, s chord.Peer, id chord.ID) (chord.Pe
|
|||||||
url := url.URL{
|
url := url.URL{
|
||||||
Scheme: "http",
|
Scheme: "http",
|
||||||
Host: addr.String(),
|
Host: addr.String(),
|
||||||
Path: path.Join("/", cl.APIBase, "key"),
|
Path: path.Join("/", cl.APIBase, "key", id.String()),
|
||||||
RawQuery: url.Values{"s": {id.String()}}.Encode(),
|
|
||||||
}
|
}
|
||||||
req, err := http.NewRequestWithContext(ctx, "GET", url.String(), nil)
|
req, err := http.NewRequestWithContext(ctx, "GET", url.String(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -45,7 +45,7 @@ func New(l net.Listener, cl chord.Client) (*Node, error) {
|
|||||||
// Router creates a handler for the Chord HTTP endpoints.
|
// Router creates a handler for the Chord HTTP endpoints.
|
||||||
func (n *Node) Router() http.Handler {
|
func (n *Node) Router() http.Handler {
|
||||||
m := http.NewServeMux()
|
m := http.NewServeMux()
|
||||||
m.HandleFunc("GET /key", n.key)
|
m.HandleFunc("GET /key/{id}", n.key)
|
||||||
m.HandleFunc("POST /pred", n.notify)
|
m.HandleFunc("POST /pred", n.notify)
|
||||||
m.HandleFunc("GET /neighbors", n.neighbors)
|
m.HandleFunc("GET /neighbors", n.neighbors)
|
||||||
return m
|
return m
|
||||||
@ -66,7 +66,7 @@ func (n *Node) Check(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) key(w http.ResponseWriter, r *http.Request) {
|
func (n *Node) key(w http.ResponseWriter, r *http.Request) {
|
||||||
s := r.FormValue("s")
|
s := r.PathValue("id")
|
||||||
id, err := chord.ParseID(s)
|
id, err := chord.ParseID(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusBadRequest, err.Error())
|
writeError(w, http.StatusBadRequest, err.Error())
|
||||||
|
Loading…
Reference in New Issue
Block a user