github.com/cobalt77/jfrog-client-go@v0.14.5/artifactory/services/readfile.go (about) 1 package services 2 3 import ( 4 "io" 5 "net/http" 6 7 rthttpclient "github.com/cobalt77/jfrog-client-go/artifactory/httpclient" 8 "github.com/cobalt77/jfrog-client-go/artifactory/services/utils" 9 "github.com/cobalt77/jfrog-client-go/auth" 10 "github.com/cobalt77/jfrog-client-go/utils/errorutils" 11 ) 12 13 type ReadFileService struct { 14 client *rthttpclient.ArtifactoryHttpClient 15 ArtDetails auth.ServiceDetails 16 DryRun bool 17 MinSplitSize int64 18 SplitCount int 19 } 20 21 func NewReadFileService(client *rthttpclient.ArtifactoryHttpClient) *ReadFileService { 22 return &ReadFileService{client: client} 23 } 24 25 func (ds *ReadFileService) GetArtifactoryDetails() auth.ServiceDetails { 26 return ds.ArtDetails 27 } 28 29 func (ds *ReadFileService) SetArtifactoryDetails(rt auth.ServiceDetails) { 30 ds.ArtDetails = rt 31 } 32 33 func (ds *ReadFileService) IsDryRun() bool { 34 return ds.DryRun 35 } 36 37 func (ds *ReadFileService) GetJfrogHttpClient() (*rthttpclient.ArtifactoryHttpClient, error) { 38 return ds.client, nil 39 } 40 41 func (ds *ReadFileService) SetServiceDetails(artDetails auth.ServiceDetails) { 42 ds.ArtDetails = artDetails 43 } 44 45 func (ds *ReadFileService) SetDryRun(isDryRun bool) { 46 ds.DryRun = isDryRun 47 } 48 49 func (ds *ReadFileService) setMinSplitSize(minSplitSize int64) { 50 ds.MinSplitSize = minSplitSize 51 } 52 53 func (ds *ReadFileService) ReadRemoteFile(downloadPath string) (io.ReadCloser, error) { 54 readPath, err := utils.BuildArtifactoryUrl(ds.ArtDetails.GetUrl(), downloadPath, make(map[string]string)) 55 if err != nil { 56 return nil, err 57 } 58 httpClientsDetails := ds.ArtDetails.CreateHttpClientDetails() 59 ioReadCloser, resp, err := ds.client.ReadRemoteFile(readPath, &httpClientsDetails) 60 if err != nil { 61 return nil, err 62 } 63 err = errorutils.CheckResponseStatus(resp, http.StatusOK) 64 if err != nil { 65 return nil, err 66 } 67 return ioReadCloser, err 68 }