api/cluster.go
func deleteCluster(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	allowed := permission.Check(t, permission.PermClusterDelete)
	if !allowed {
		return permission.ErrUnauthorized
	}

	clusterName := r.URL.Query().Get(":name")
	evt, err := event.New(&event.Opts{
		Target:     event.Target{Type: event.TargetTypeCluster, Value: clusterName},
		Kind:       permission.PermClusterDelete,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermClusterReadEvents),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	streamResponse := strings.HasPrefix(r.Header.Get("Accept"), "application/x-json-stream")
	if streamResponse {
		w.Header().Set("Content-Type", "application/x-json-stream")
		keepAliveWriter := tsuruIo.NewKeepAliveWriter(w, 30*time.Second, "")
		defer keepAliveWriter.Stop()
		writer := &tsuruIo.SimpleJsonMessageEncoderWriter{Encoder: json.NewEncoder(keepAliveWriter)}
		evt.SetLogWriter(writer)
	}
	err = servicemanager.Cluster.Delete(provTypes.Cluster{Name: clusterName, Writer: evt})
	if err != nil {
		if errors.Cause(err) == provTypes.ErrClusterNotFound {
			return &tsuruErrors.HTTP{
				Code:    http.StatusNotFound,
				Message: err.Error(),
			}
		}
		return err
	}
	return nil
}
func deleteCluster(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	allowed := permission.Check(t, permission.PermClusterDelete)
	if !allowed {
		return permission.ErrUnauthorized
	}

	clusterName := r.URL.Query().Get(":name")
	evt, err := event.New(&event.Opts{
		Target:     event.Target{Type: event.TargetTypeCluster, Value: clusterName},
		Kind:       permission.PermClusterDelete,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermClusterReadEvents),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	streamResponse := strings.HasPrefix(r.Header.Get("Accept"), "application/x-json-stream")
	if streamResponse {
		w.Header().Set("Content-Type", "application/x-json-stream")
		keepAliveWriter := tsuruIo.NewKeepAliveWriter(w, 30*time.Second, "")
		defer keepAliveWriter.Stop()
		writer := &tsuruIo.SimpleJsonMessageEncoderWriter{Encoder: json.NewEncoder(keepAliveWriter)}
		evt.SetLogWriter(writer)
	}
	err = servicemanager.Cluster.Delete(provTypes.Cluster{Name: clusterName, Writer: evt})
	if err != nil {
		if errors.Cause(err) == provTypes.ErrClusterNotFound {
			return &tsuruErrors.HTTP{
				Code:    http.StatusNotFound,
				Message: err.Error(),
			}
		}
		return err
	}
	return nil
}
// title: delete provisioner cluster
// path: /provisioner/clusters/{name}
// method: DELETE
// consume: application/x-www-form-urlencoded
// produce: application/x-json-stream
// responses:
//   200: Ok
//   401: Unauthorized
//   404: Cluster not found