delete

package
v1.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2021 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Cmd = &cobra.Command{
		Use:       "delete [RESOURCE]",
		Short:     "Delete one resource",
		ValidArgs: []string{"tasks", "results", "goals"},
		Args:      cobra.ExactArgs(2),
		Aliases:   []string{"del", "remove"},
		Run: func(cmd *cobra.Command, args []string) {
			resource := args[0]
			id := args[1]

			uri := fmt.Sprintf("%v/v1/%v/%v", cfg.API.EndPoint, resource, id)
			req, err := http.NewRequest(http.MethodDelete, uri, nil)
			if err != nil {
				fmt.Println(err)
				return
			}

			client := &http.Client{}
			resp, err := client.Do(req)
			if err != nil {
				fmt.Println(err)
				return
			}
			defer resp.Body.Close()

			if resp.StatusCode == http.StatusNoContent {
				fmt.Printf("Delete %v ID: %v is success\n", resource, id)
			}
		},
	}
)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL