github.com/cobalt77/jfrog-client-go@v0.14.5/artifactory/services/deleterepository.go (about) 1 package services 2 3 import ( 4 "errors" 5 "net/http" 6 7 rthttpclient "github.com/cobalt77/jfrog-client-go/artifactory/httpclient" 8 "github.com/cobalt77/jfrog-client-go/auth" 9 clientutils "github.com/cobalt77/jfrog-client-go/utils" 10 "github.com/cobalt77/jfrog-client-go/utils/errorutils" 11 "github.com/cobalt77/jfrog-client-go/utils/log" 12 ) 13 14 type DeleteRepositoryService struct { 15 client *rthttpclient.ArtifactoryHttpClient 16 ArtDetails auth.ServiceDetails 17 } 18 19 func NewDeleteRepositoryService(client *rthttpclient.ArtifactoryHttpClient) *DeleteRepositoryService { 20 return &DeleteRepositoryService{client: client} 21 } 22 23 func (drs *DeleteRepositoryService) GetJfrogHttpClient() *rthttpclient.ArtifactoryHttpClient { 24 return drs.client 25 } 26 27 func (drs *DeleteRepositoryService) Delete(repoKey string) error { 28 httpClientsDetails := drs.ArtDetails.CreateHttpClientDetails() 29 log.Info("Deleting repository...") 30 resp, body, err := drs.client.SendDelete(drs.ArtDetails.GetUrl()+"api/repositories/"+repoKey, nil, &httpClientsDetails) 31 if err != nil { 32 return err 33 } 34 if resp.StatusCode != http.StatusOK { 35 return errorutils.CheckError(errors.New("Artifactory response: " + resp.Status + "\n" + clientutils.IndentJson(body))) 36 } 37 38 log.Debug("Artifactory response:", resp.Status) 39 log.Info("Done deleting repository.") 40 return nil 41 }