Detailed changes
@@ -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)
@@ -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) {
@@ -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)