github.com/supabase/cli@v1.168.1/internal/functions/delete/delete.go (about)

     1  package delete
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"net/http"
     7  
     8  	"github.com/go-errors/errors"
     9  	"github.com/spf13/afero"
    10  	"github.com/supabase/cli/internal/utils"
    11  )
    12  
    13  func Run(ctx context.Context, slug string, projectRef string, fsys afero.Fs) error {
    14  	// 1. Sanity checks.
    15  	{
    16  		if err := utils.ValidateFunctionSlug(slug); err != nil {
    17  			return err
    18  		}
    19  	}
    20  
    21  	// 2. Delete Function.
    22  	resp, err := utils.GetSupabase().DeleteFunctionWithResponse(ctx, projectRef, slug)
    23  	if err != nil {
    24  		return errors.Errorf("failed to delete function: %w", err)
    25  	}
    26  	switch resp.StatusCode() {
    27  	case http.StatusNotFound:
    28  		return errors.New("Function " + utils.Aqua(slug) + " does not exist on the Supabase project.")
    29  	case http.StatusOK:
    30  		break
    31  	default:
    32  		return errors.New("Failed to delete Function " + utils.Aqua(slug) + " on the Supabase project: " + string(resp.Body))
    33  	}
    34  
    35  	fmt.Println("Deleted Function " + utils.Aqua(slug) + " from project " + utils.Aqua(projectRef) + ".")
    36  	return nil
    37  }