use path values instead of query parameters for lookup

This commit is contained in:
Branden J Brown 2025-03-13 21:07:10 -04:00
parent 8047f4f13e
commit 4b44ffcd13
2 changed files with 5 additions and 6 deletions

View File

@ -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 {

View File

@ -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())