diff --git a/internal/client/proto.go b/internal/client/proto.go index 64dc542b307ff454fc7cf7b037e3c2eedb22c491..09ad5d379dbdef985a31bbb0926fca9c81624887 100644 --- a/internal/client/proto.go +++ b/internal/client/proto.go @@ -547,23 +547,6 @@ func (c *Client) DeleteInstance(ctx context.Context, id string) error { return nil } -func (c *Client) DeleteInstances(ctx context.Context, ids []string) error { - r, err := http.NewRequestWithContext(ctx, "DELETE", "http://localhost/v1/instances", jsonBody(ids)) - if err != nil { - return fmt.Errorf("failed to create request: %w", err) - } - r.Header.Set("Content-Type", "application/json") - rsp, err := c.h.Do(r) - if err != nil { - return fmt.Errorf("failed to delete instances: %w", err) - } - defer rsp.Body.Close() - if rsp.StatusCode != http.StatusOK { - return fmt.Errorf("failed to delete instances: status code %d", rsp.StatusCode) - } - return nil -} - func jsonBody(v any) *bytes.Buffer { b := new(bytes.Buffer) m, _ := json.Marshal(v) diff --git a/internal/server/proto.go b/internal/server/proto.go index 40bcba880646176cba10c775c854bbc57740e64c..d4da17bbdda243067cae571c74b825be289168e2 100644 --- a/internal/server/proto.go +++ b/internal/server/proto.go @@ -504,34 +504,12 @@ func (c *controllerV1) handleGetInstanceConfig(w http.ResponseWriter, r *http.Re } func (c *controllerV1) handleDeleteInstances(w http.ResponseWriter, r *http.Request) { - var ids []string - id := r.URL.Query().Get("id") - if id != "" { - ids = append(ids, id) - } - - // Get IDs from body - var args []proto.Instance - if err := json.NewDecoder(r.Body).Decode(&args); err != nil { - c.logError(r, "failed to decode request", "error", err) - jsonError(w, http.StatusBadRequest, "failed to decode request") - return - } - ids = append(ids, func() []string { - out := make([]string, len(args)) - for i, arg := range args { - out[i] = arg.ID - } - return out - }()...) - - for _, id := range ids { - ins, ok := c.instances.Get(id) - if ok { - ins.App.Shutdown() - } - c.instances.Del(id) + id := r.PathValue("id") + ins, ok := c.instances.Get(id) + if ok { + ins.App.Shutdown() } + c.instances.Del(id) } func (c *controllerV1) handlePostInstances(w http.ResponseWriter, r *http.Request) { diff --git a/internal/server/server.go b/internal/server/server.go index d4599860d09be6387c754d7122d3515025167259..345850167ab48f08bf4f4a718c6a4a7e569b37ac 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -138,7 +138,7 @@ func NewServer(cfg *config.Config, network, address string) *Server { mux.HandleFunc("POST /v1/control", c.handlePostControl) mux.HandleFunc("GET /v1/instances", c.handleGetInstances) mux.HandleFunc("POST /v1/instances", c.handlePostInstances) - mux.HandleFunc("DELETE /v1/instances", c.handleDeleteInstances) + mux.HandleFunc("DELETE /v1/instances/{id}", c.handleDeleteInstances) mux.HandleFunc("GET /v1/instances/{id}/config", c.handleGetInstanceConfig) mux.HandleFunc("GET /v1/instances/{id}/events", c.handleGetInstanceEvents) mux.HandleFunc("GET /v1/instances/{id}/sessions", c.handleGetInstanceSessions)