- store/sqlite: 75.4% (repos + db coverage) - host/sub2api: 80.8% (httptest mock server, pure function tests) - app: 74.2% (handler error paths, NewActionSet closures) - pack: 72.4% - provision: 75.2% - access: 77.3% - config: 94.7% (lookup mock tests) All tests pass: build, vet, race, coverage gates.
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package sub2api
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func (c *Client) DeleteGroup(ctx context.Context, groupID string) error {
|
|
return c.deleteResource(ctx, "/api/v1/admin/groups/", groupID)
|
|
}
|
|
|
|
func (c *Client) DeleteChannel(ctx context.Context, channelID string) error {
|
|
return c.deleteResource(ctx, "/api/v1/admin/channels/", channelID)
|
|
}
|
|
|
|
func (c *Client) DeletePlan(ctx context.Context, planID string) error {
|
|
return c.deleteResource(ctx, "/api/v1/admin/payment/plans/", planID)
|
|
}
|
|
|
|
func (c *Client) DeleteAccount(ctx context.Context, accountID string) error {
|
|
return c.deleteResource(ctx, "/api/v1/admin/accounts/", accountID)
|
|
}
|
|
|
|
func (c *Client) deleteResource(ctx context.Context, prefix, resourceID string) error {
|
|
resourceID = strings.TrimSpace(resourceID)
|
|
if resourceID == "" {
|
|
return fmt.Errorf("resource id is required")
|
|
}
|
|
path := prefix + resourceID
|
|
statusCode, _, body, err := c.perform(ctx, http.MethodDelete, path, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if statusCode < http.StatusOK || statusCode >= http.StatusMultipleChoices {
|
|
return newHTTPError(http.MethodDelete, path, statusCode, body)
|
|
}
|
|
return nil
|
|
}
|