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