client.go 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  1. // Package oss implements functions for access oss service.
  2. // It has two main struct Client and Bucket.
  3. package oss
  4. import (
  5. "bytes"
  6. "encoding/xml"
  7. "fmt"
  8. "io"
  9. "io/ioutil"
  10. "log"
  11. "net/http"
  12. "strings"
  13. "time"
  14. )
  15. // Client SDK's entry point. It's for bucket related options such as create/delete/set bucket (such as set/get ACL/lifecycle/referer/logging/website).
  16. // Object related operations are done by Bucket class.
  17. // Users use oss.New to create Client instance.
  18. //
  19. type (
  20. // Client OSS client
  21. Client struct {
  22. Config *Config // OSS client configuration
  23. Conn *Conn // Send HTTP request
  24. HTTPClient *http.Client //http.Client to use - if nil will make its own
  25. }
  26. // ClientOption client option such as UseCname, Timeout, SecurityToken.
  27. ClientOption func(*Client)
  28. )
  29. // New creates a new client.
  30. //
  31. // endpoint the OSS datacenter endpoint such as http://oss-cn-hangzhou.aliyuncs.com .
  32. // accessKeyId access key Id.
  33. // accessKeySecret access key secret.
  34. //
  35. // Client creates the new client instance, the returned value is valid when error is nil.
  36. // error it's nil if no error, otherwise it's an error object.
  37. //
  38. func New(endpoint, accessKeyID, accessKeySecret string, options ...ClientOption) (*Client, error) {
  39. // Configuration
  40. config := getDefaultOssConfig()
  41. config.Endpoint = endpoint
  42. config.AccessKeyID = accessKeyID
  43. config.AccessKeySecret = accessKeySecret
  44. // URL parse
  45. url := &urlMaker{}
  46. url.Init(config.Endpoint, config.IsCname, config.IsUseProxy)
  47. // HTTP connect
  48. conn := &Conn{config: config, url: url}
  49. // OSS client
  50. client := &Client{
  51. Config: config,
  52. Conn: conn,
  53. }
  54. // Client options parse
  55. for _, option := range options {
  56. option(client)
  57. }
  58. // Create HTTP connection
  59. err := conn.init(config, url, client.HTTPClient)
  60. return client, err
  61. }
  62. // Bucket gets the bucket instance.
  63. //
  64. // bucketName the bucket name.
  65. // Bucket the bucket object, when error is nil.
  66. //
  67. // error it's nil if no error, otherwise it's an error object.
  68. //
  69. func (client Client) Bucket(bucketName string) (*Bucket, error) {
  70. return &Bucket{
  71. client,
  72. bucketName,
  73. }, nil
  74. }
  75. // CreateBucket creates a bucket.
  76. //
  77. // bucketName the bucket name, it's globably unique and immutable. The bucket name can only consist of lowercase letters, numbers and dash ('-').
  78. // It must start with lowercase letter or number and the length can only be between 3 and 255.
  79. // options options for creating the bucket, with optional ACL. The ACL could be ACLPrivate, ACLPublicRead, and ACLPublicReadWrite. By default it's ACLPrivate.
  80. // It could also be specified with StorageClass option, which supports StorageStandard, StorageIA(infrequent access), StorageArchive.
  81. //
  82. // error it's nil if no error, otherwise it's an error object.
  83. //
  84. func (client Client) CreateBucket(bucketName string, options ...Option) error {
  85. headers := make(map[string]string)
  86. handleOptions(headers, options)
  87. buffer := new(bytes.Buffer)
  88. isOptSet, val, _ := isOptionSet(options, storageClass)
  89. if isOptSet {
  90. cbConfig := createBucketConfiguration{StorageClass: val.(StorageClassType)}
  91. bs, err := xml.Marshal(cbConfig)
  92. if err != nil {
  93. return err
  94. }
  95. buffer.Write(bs)
  96. contentType := http.DetectContentType(buffer.Bytes())
  97. headers[HTTPHeaderContentType] = contentType
  98. }
  99. params := map[string]interface{}{}
  100. resp, err := client.do("PUT", bucketName, params, headers, buffer, options...)
  101. if err != nil {
  102. return err
  103. }
  104. defer resp.Body.Close()
  105. return checkRespCode(resp.StatusCode, []int{http.StatusOK})
  106. }
  107. // ListBuckets lists buckets of the current account under the given endpoint, with optional filters.
  108. //
  109. // options specifies the filters such as Prefix, Marker and MaxKeys. Prefix is the bucket name's prefix filter.
  110. // And marker makes sure the returned buckets' name are greater than it in lexicographic order.
  111. // Maxkeys limits the max keys to return, and by default it's 100 and up to 1000.
  112. // For the common usage scenario, please check out list_bucket.go in the sample.
  113. // ListBucketsResponse the response object if error is nil.
  114. //
  115. // error it's nil if no error, otherwise it's an error object.
  116. //
  117. func (client Client) ListBuckets(options ...Option) (ListBucketsResult, error) {
  118. var out ListBucketsResult
  119. params, err := getRawParams(options)
  120. if err != nil {
  121. return out, err
  122. }
  123. resp, err := client.do("GET", "", params, nil, nil, options...)
  124. if err != nil {
  125. return out, err
  126. }
  127. defer resp.Body.Close()
  128. err = xmlUnmarshal(resp.Body, &out)
  129. return out, err
  130. }
  131. // IsBucketExist checks if the bucket exists
  132. //
  133. // bucketName the bucket name.
  134. //
  135. // bool true if it exists, and it's only valid when error is nil.
  136. // error it's nil if no error, otherwise it's an error object.
  137. //
  138. func (client Client) IsBucketExist(bucketName string) (bool, error) {
  139. listRes, err := client.ListBuckets(Prefix(bucketName), MaxKeys(1))
  140. if err != nil {
  141. return false, err
  142. }
  143. if len(listRes.Buckets) == 1 && listRes.Buckets[0].Name == bucketName {
  144. return true, nil
  145. }
  146. return false, nil
  147. }
  148. // DeleteBucket deletes the bucket. Only empty bucket can be deleted (no object and parts).
  149. //
  150. // bucketName the bucket name.
  151. //
  152. // error it's nil if no error, otherwise it's an error object.
  153. //
  154. func (client Client) DeleteBucket(bucketName string) error {
  155. params := map[string]interface{}{}
  156. resp, err := client.do("DELETE", bucketName, params, nil, nil)
  157. if err != nil {
  158. return err
  159. }
  160. defer resp.Body.Close()
  161. return checkRespCode(resp.StatusCode, []int{http.StatusNoContent})
  162. }
  163. // GetBucketLocation gets the bucket location.
  164. //
  165. // Checks out the following link for more information :
  166. // https://help.aliyun.com/document_detail/oss/user_guide/oss_concept/endpoint.html
  167. //
  168. // bucketName the bucket name
  169. //
  170. // string bucket's datacenter location
  171. // error it's nil if no error, otherwise it's an error object.
  172. //
  173. func (client Client) GetBucketLocation(bucketName string) (string, error) {
  174. params := map[string]interface{}{}
  175. params["location"] = nil
  176. resp, err := client.do("GET", bucketName, params, nil, nil)
  177. if err != nil {
  178. return "", err
  179. }
  180. defer resp.Body.Close()
  181. var LocationConstraint string
  182. err = xmlUnmarshal(resp.Body, &LocationConstraint)
  183. return LocationConstraint, err
  184. }
  185. // SetBucketACL sets bucket's ACL.
  186. //
  187. // bucketName the bucket name
  188. // bucketAcl the bucket ACL: ACLPrivate, ACLPublicRead and ACLPublicReadWrite.
  189. //
  190. // error it's nil if no error, otherwise it's an error object.
  191. //
  192. func (client Client) SetBucketACL(bucketName string, bucketACL ACLType) error {
  193. headers := map[string]string{HTTPHeaderOssACL: string(bucketACL)}
  194. params := map[string]interface{}{}
  195. params["acl"] = nil
  196. resp, err := client.do("PUT", bucketName, params, headers, nil)
  197. if err != nil {
  198. return err
  199. }
  200. defer resp.Body.Close()
  201. return checkRespCode(resp.StatusCode, []int{http.StatusOK})
  202. }
  203. // GetBucketACL gets the bucket ACL.
  204. //
  205. // bucketName the bucket name.
  206. //
  207. // GetBucketAclResponse the result object, and it's only valid when error is nil.
  208. // error it's nil if no error, otherwise it's an error object.
  209. //
  210. func (client Client) GetBucketACL(bucketName string) (GetBucketACLResult, error) {
  211. var out GetBucketACLResult
  212. params := map[string]interface{}{}
  213. params["acl"] = nil
  214. resp, err := client.do("GET", bucketName, params, nil, nil)
  215. if err != nil {
  216. return out, err
  217. }
  218. defer resp.Body.Close()
  219. err = xmlUnmarshal(resp.Body, &out)
  220. return out, err
  221. }
  222. // SetBucketLifecycle sets the bucket's lifecycle.
  223. //
  224. // For more information, checks out following link:
  225. // https://help.aliyun.com/document_detail/oss/user_guide/manage_object/object_lifecycle.html
  226. //
  227. // bucketName the bucket name.
  228. // rules the lifecycle rules. There're two kind of rules: absolute time expiration and relative time expiration in days and day/month/year respectively.
  229. // Check out sample/bucket_lifecycle.go for more details.
  230. //
  231. // error it's nil if no error, otherwise it's an error object.
  232. //
  233. func (client Client) SetBucketLifecycle(bucketName string, rules []LifecycleRule) error {
  234. err := verifyLifecycleRules(rules)
  235. if err != nil {
  236. return err
  237. }
  238. lifecycleCfg := LifecycleConfiguration{Rules: rules}
  239. bs, err := xml.Marshal(lifecycleCfg)
  240. if err != nil {
  241. return err
  242. }
  243. buffer := new(bytes.Buffer)
  244. buffer.Write(bs)
  245. contentType := http.DetectContentType(buffer.Bytes())
  246. headers := map[string]string{}
  247. headers[HTTPHeaderContentType] = contentType
  248. params := map[string]interface{}{}
  249. params["lifecycle"] = nil
  250. resp, err := client.do("PUT", bucketName, params, headers, buffer)
  251. if err != nil {
  252. return err
  253. }
  254. defer resp.Body.Close()
  255. return checkRespCode(resp.StatusCode, []int{http.StatusOK})
  256. }
  257. // DeleteBucketLifecycle deletes the bucket's lifecycle.
  258. //
  259. //
  260. // bucketName the bucket name.
  261. //
  262. // error it's nil if no error, otherwise it's an error object.
  263. //
  264. func (client Client) DeleteBucketLifecycle(bucketName string) error {
  265. params := map[string]interface{}{}
  266. params["lifecycle"] = nil
  267. resp, err := client.do("DELETE", bucketName, params, nil, nil)
  268. if err != nil {
  269. return err
  270. }
  271. defer resp.Body.Close()
  272. return checkRespCode(resp.StatusCode, []int{http.StatusNoContent})
  273. }
  274. // GetBucketLifecycle gets the bucket's lifecycle settings.
  275. //
  276. // bucketName the bucket name.
  277. //
  278. // GetBucketLifecycleResponse the result object upon successful request. It's only valid when error is nil.
  279. // error it's nil if no error, otherwise it's an error object.
  280. //
  281. func (client Client) GetBucketLifecycle(bucketName string) (GetBucketLifecycleResult, error) {
  282. var out GetBucketLifecycleResult
  283. params := map[string]interface{}{}
  284. params["lifecycle"] = nil
  285. resp, err := client.do("GET", bucketName, params, nil, nil)
  286. if err != nil {
  287. return out, err
  288. }
  289. defer resp.Body.Close()
  290. err = xmlUnmarshal(resp.Body, &out)
  291. return out, err
  292. }
  293. // SetBucketReferer sets the bucket's referer whitelist and the flag if allowing empty referrer.
  294. //
  295. // To avoid stealing link on OSS data, OSS supports the HTTP referrer header. A whitelist referrer could be set either by API or web console, as well as
  296. // the allowing empty referrer flag. Note that this applies to requests from webbrowser only.
  297. // For example, for a bucket os-example and its referrer http://www.aliyun.com, all requests from this URL could access the bucket.
  298. // For more information, please check out this link :
  299. // https://help.aliyun.com/document_detail/oss/user_guide/security_management/referer.html
  300. //
  301. // bucketName the bucket name.
  302. // referers the referrer white list. A bucket could have a referrer list and each referrer supports one '*' and multiple '?' as wildcards.
  303. // The sample could be found in sample/bucket_referer.go
  304. // allowEmptyReferer the flag of allowing empty referrer. By default it's true.
  305. //
  306. // error it's nil if no error, otherwise it's an error object.
  307. //
  308. func (client Client) SetBucketReferer(bucketName string, referers []string, allowEmptyReferer bool) error {
  309. rxml := RefererXML{}
  310. rxml.AllowEmptyReferer = allowEmptyReferer
  311. if referers == nil {
  312. rxml.RefererList = append(rxml.RefererList, "")
  313. } else {
  314. for _, referer := range referers {
  315. rxml.RefererList = append(rxml.RefererList, referer)
  316. }
  317. }
  318. bs, err := xml.Marshal(rxml)
  319. if err != nil {
  320. return err
  321. }
  322. buffer := new(bytes.Buffer)
  323. buffer.Write(bs)
  324. contentType := http.DetectContentType(buffer.Bytes())
  325. headers := map[string]string{}
  326. headers[HTTPHeaderContentType] = contentType
  327. params := map[string]interface{}{}
  328. params["referer"] = nil
  329. resp, err := client.do("PUT", bucketName, params, headers, buffer)
  330. if err != nil {
  331. return err
  332. }
  333. defer resp.Body.Close()
  334. return checkRespCode(resp.StatusCode, []int{http.StatusOK})
  335. }
  336. // GetBucketReferer gets the bucket's referrer white list.
  337. //
  338. // bucketName the bucket name.
  339. //
  340. // GetBucketRefererResponse the result object upon successful request. It's only valid when error is nil.
  341. // error it's nil if no error, otherwise it's an error object.
  342. //
  343. func (client Client) GetBucketReferer(bucketName string) (GetBucketRefererResult, error) {
  344. var out GetBucketRefererResult
  345. params := map[string]interface{}{}
  346. params["referer"] = nil
  347. resp, err := client.do("GET", bucketName, params, nil, nil)
  348. if err != nil {
  349. return out, err
  350. }
  351. defer resp.Body.Close()
  352. err = xmlUnmarshal(resp.Body, &out)
  353. return out, err
  354. }
  355. // SetBucketLogging sets the bucket logging settings.
  356. //
  357. // OSS could automatically store the access log. Only the bucket owner could enable the logging.
  358. // Once enabled, OSS would save all the access log into hourly log files in a specified bucket.
  359. // For more information, please check out https://help.aliyun.com/document_detail/oss/user_guide/security_management/logging.html
  360. //
  361. // bucketName bucket name to enable the log.
  362. // targetBucket the target bucket name to store the log files.
  363. // targetPrefix the log files' prefix.
  364. //
  365. // error it's nil if no error, otherwise it's an error object.
  366. //
  367. func (client Client) SetBucketLogging(bucketName, targetBucket, targetPrefix string,
  368. isEnable bool) error {
  369. var err error
  370. var bs []byte
  371. if isEnable {
  372. lxml := LoggingXML{}
  373. lxml.LoggingEnabled.TargetBucket = targetBucket
  374. lxml.LoggingEnabled.TargetPrefix = targetPrefix
  375. bs, err = xml.Marshal(lxml)
  376. } else {
  377. lxml := loggingXMLEmpty{}
  378. bs, err = xml.Marshal(lxml)
  379. }
  380. if err != nil {
  381. return err
  382. }
  383. buffer := new(bytes.Buffer)
  384. buffer.Write(bs)
  385. contentType := http.DetectContentType(buffer.Bytes())
  386. headers := map[string]string{}
  387. headers[HTTPHeaderContentType] = contentType
  388. params := map[string]interface{}{}
  389. params["logging"] = nil
  390. resp, err := client.do("PUT", bucketName, params, headers, buffer)
  391. if err != nil {
  392. return err
  393. }
  394. defer resp.Body.Close()
  395. return checkRespCode(resp.StatusCode, []int{http.StatusOK})
  396. }
  397. // DeleteBucketLogging deletes the logging configuration to disable the logging on the bucket.
  398. //
  399. // bucketName the bucket name to disable the logging.
  400. //
  401. // error it's nil if no error, otherwise it's an error object.
  402. //
  403. func (client Client) DeleteBucketLogging(bucketName string) error {
  404. params := map[string]interface{}{}
  405. params["logging"] = nil
  406. resp, err := client.do("DELETE", bucketName, params, nil, nil)
  407. if err != nil {
  408. return err
  409. }
  410. defer resp.Body.Close()
  411. return checkRespCode(resp.StatusCode, []int{http.StatusNoContent})
  412. }
  413. // GetBucketLogging gets the bucket's logging settings
  414. //
  415. // bucketName the bucket name
  416. // GetBucketLoggingResponse the result object upon successful request. It's only valid when error is nil.
  417. //
  418. // error it's nil if no error, otherwise it's an error object.
  419. //
  420. func (client Client) GetBucketLogging(bucketName string) (GetBucketLoggingResult, error) {
  421. var out GetBucketLoggingResult
  422. params := map[string]interface{}{}
  423. params["logging"] = nil
  424. resp, err := client.do("GET", bucketName, params, nil, nil)
  425. if err != nil {
  426. return out, err
  427. }
  428. defer resp.Body.Close()
  429. err = xmlUnmarshal(resp.Body, &out)
  430. return out, err
  431. }
  432. // SetBucketWebsite sets the bucket's static website's index and error page.
  433. //
  434. // OSS supports static web site hosting for the bucket data. When the bucket is enabled with that, you can access the file in the bucket like the way to access a static website.
  435. // For more information, please check out: https://help.aliyun.com/document_detail/oss/user_guide/static_host_website.html
  436. //
  437. // bucketName the bucket name to enable static web site.
  438. // indexDocument index page.
  439. // errorDocument error page.
  440. //
  441. // error it's nil if no error, otherwise it's an error object.
  442. //
  443. func (client Client) SetBucketWebsite(bucketName, indexDocument, errorDocument string) error {
  444. wxml := WebsiteXML{}
  445. wxml.IndexDocument.Suffix = indexDocument
  446. wxml.ErrorDocument.Key = errorDocument
  447. bs, err := xml.Marshal(wxml)
  448. if err != nil {
  449. return err
  450. }
  451. buffer := new(bytes.Buffer)
  452. buffer.Write(bs)
  453. contentType := http.DetectContentType(buffer.Bytes())
  454. headers := make(map[string]string)
  455. headers[HTTPHeaderContentType] = contentType
  456. params := map[string]interface{}{}
  457. params["website"] = nil
  458. resp, err := client.do("PUT", bucketName, params, headers, buffer)
  459. if err != nil {
  460. return err
  461. }
  462. defer resp.Body.Close()
  463. return checkRespCode(resp.StatusCode, []int{http.StatusOK})
  464. }
  465. // SetBucketWebsiteDetail sets the bucket's static website's detail
  466. //
  467. // OSS supports static web site hosting for the bucket data. When the bucket is enabled with that, you can access the file in the bucket like the way to access a static website.
  468. // For more information, please check out: https://help.aliyun.com/document_detail/oss/user_guide/static_host_website.html
  469. //
  470. // bucketName the bucket name to enable static web site.
  471. //
  472. // wxml the website's detail
  473. //
  474. // error it's nil if no error, otherwise it's an error object.
  475. //
  476. func (client Client) SetBucketWebsiteDetail(bucketName string, wxml WebsiteXML, options ...Option) error {
  477. bs, err := xml.Marshal(wxml)
  478. if err != nil {
  479. return err
  480. }
  481. buffer := new(bytes.Buffer)
  482. buffer.Write(bs)
  483. contentType := http.DetectContentType(buffer.Bytes())
  484. headers := make(map[string]string)
  485. headers[HTTPHeaderContentType] = contentType
  486. params := map[string]interface{}{}
  487. params["website"] = nil
  488. resp, err := client.do("PUT", bucketName, params, headers, buffer, options...)
  489. if err != nil {
  490. return err
  491. }
  492. defer resp.Body.Close()
  493. return checkRespCode(resp.StatusCode, []int{http.StatusOK})
  494. }
  495. // DeleteBucketWebsite deletes the bucket's static web site settings.
  496. //
  497. // bucketName the bucket name.
  498. //
  499. // error it's nil if no error, otherwise it's an error object.
  500. //
  501. func (client Client) DeleteBucketWebsite(bucketName string) error {
  502. params := map[string]interface{}{}
  503. params["website"] = nil
  504. resp, err := client.do("DELETE", bucketName, params, nil, nil)
  505. if err != nil {
  506. return err
  507. }
  508. defer resp.Body.Close()
  509. return checkRespCode(resp.StatusCode, []int{http.StatusNoContent})
  510. }
  511. // GetBucketWebsite gets the bucket's default page (index page) and the error page.
  512. //
  513. // bucketName the bucket name
  514. //
  515. // GetBucketWebsiteResponse the result object upon successful request. It's only valid when error is nil.
  516. // error it's nil if no error, otherwise it's an error object.
  517. //
  518. func (client Client) GetBucketWebsite(bucketName string) (GetBucketWebsiteResult, error) {
  519. var out GetBucketWebsiteResult
  520. params := map[string]interface{}{}
  521. params["website"] = nil
  522. resp, err := client.do("GET", bucketName, params, nil, nil)
  523. if err != nil {
  524. return out, err
  525. }
  526. defer resp.Body.Close()
  527. err = xmlUnmarshal(resp.Body, &out)
  528. return out, err
  529. }
  530. // SetBucketCORS sets the bucket's CORS rules
  531. //
  532. // For more information, please check out https://help.aliyun.com/document_detail/oss/user_guide/security_management/cors.html
  533. //
  534. // bucketName the bucket name
  535. // corsRules the CORS rules to set. The related sample code is in sample/bucket_cors.go.
  536. //
  537. // error it's nil if no error, otherwise it's an error object.
  538. //
  539. func (client Client) SetBucketCORS(bucketName string, corsRules []CORSRule) error {
  540. corsxml := CORSXML{}
  541. for _, v := range corsRules {
  542. cr := CORSRule{}
  543. cr.AllowedMethod = v.AllowedMethod
  544. cr.AllowedOrigin = v.AllowedOrigin
  545. cr.AllowedHeader = v.AllowedHeader
  546. cr.ExposeHeader = v.ExposeHeader
  547. cr.MaxAgeSeconds = v.MaxAgeSeconds
  548. corsxml.CORSRules = append(corsxml.CORSRules, cr)
  549. }
  550. bs, err := xml.Marshal(corsxml)
  551. if err != nil {
  552. return err
  553. }
  554. buffer := new(bytes.Buffer)
  555. buffer.Write(bs)
  556. contentType := http.DetectContentType(buffer.Bytes())
  557. headers := map[string]string{}
  558. headers[HTTPHeaderContentType] = contentType
  559. params := map[string]interface{}{}
  560. params["cors"] = nil
  561. resp, err := client.do("PUT", bucketName, params, headers, buffer)
  562. if err != nil {
  563. return err
  564. }
  565. defer resp.Body.Close()
  566. return checkRespCode(resp.StatusCode, []int{http.StatusOK})
  567. }
  568. // DeleteBucketCORS deletes the bucket's static website settings.
  569. //
  570. // bucketName the bucket name.
  571. //
  572. // error it's nil if no error, otherwise it's an error object.
  573. //
  574. func (client Client) DeleteBucketCORS(bucketName string) error {
  575. params := map[string]interface{}{}
  576. params["cors"] = nil
  577. resp, err := client.do("DELETE", bucketName, params, nil, nil)
  578. if err != nil {
  579. return err
  580. }
  581. defer resp.Body.Close()
  582. return checkRespCode(resp.StatusCode, []int{http.StatusNoContent})
  583. }
  584. // GetBucketCORS gets the bucket's CORS settings.
  585. //
  586. // bucketName the bucket name.
  587. // GetBucketCORSResult the result object upon successful request. It's only valid when error is nil.
  588. //
  589. // error it's nil if no error, otherwise it's an error object.
  590. //
  591. func (client Client) GetBucketCORS(bucketName string) (GetBucketCORSResult, error) {
  592. var out GetBucketCORSResult
  593. params := map[string]interface{}{}
  594. params["cors"] = nil
  595. resp, err := client.do("GET", bucketName, params, nil, nil)
  596. if err != nil {
  597. return out, err
  598. }
  599. defer resp.Body.Close()
  600. err = xmlUnmarshal(resp.Body, &out)
  601. return out, err
  602. }
  603. // GetBucketInfo gets the bucket information.
  604. //
  605. // bucketName the bucket name.
  606. // GetBucketInfoResult the result object upon successful request. It's only valid when error is nil.
  607. //
  608. // error it's nil if no error, otherwise it's an error object.
  609. //
  610. func (client Client) GetBucketInfo(bucketName string) (GetBucketInfoResult, error) {
  611. var out GetBucketInfoResult
  612. params := map[string]interface{}{}
  613. params["bucketInfo"] = nil
  614. resp, err := client.do("GET", bucketName, params, nil, nil)
  615. if err != nil {
  616. return out, err
  617. }
  618. defer resp.Body.Close()
  619. err = xmlUnmarshal(resp.Body, &out)
  620. // convert None to ""
  621. if err == nil {
  622. if out.BucketInfo.SseRule.KMSMasterKeyID == "None" {
  623. out.BucketInfo.SseRule.KMSMasterKeyID = ""
  624. }
  625. if out.BucketInfo.SseRule.SSEAlgorithm == "None" {
  626. out.BucketInfo.SseRule.SSEAlgorithm = ""
  627. }
  628. }
  629. return out, err
  630. }
  631. // SetBucketVersioning set bucket versioning:Enabled、Suspended
  632. // bucketName the bucket name.
  633. // error it's nil if no error, otherwise it's an error object.
  634. func (client Client) SetBucketVersioning(bucketName string, versioningConfig VersioningConfig, options ...Option) error {
  635. var err error
  636. var bs []byte
  637. bs, err = xml.Marshal(versioningConfig)
  638. if err != nil {
  639. return err
  640. }
  641. buffer := new(bytes.Buffer)
  642. buffer.Write(bs)
  643. contentType := http.DetectContentType(buffer.Bytes())
  644. headers := map[string]string{}
  645. headers[HTTPHeaderContentType] = contentType
  646. params := map[string]interface{}{}
  647. params["versioning"] = nil
  648. resp, err := client.do("PUT", bucketName, params, headers, buffer, options...)
  649. if err != nil {
  650. return err
  651. }
  652. defer resp.Body.Close()
  653. return checkRespCode(resp.StatusCode, []int{http.StatusOK})
  654. }
  655. // GetBucketVersioning get bucket versioning status:Enabled、Suspended
  656. // bucketName the bucket name.
  657. // error it's nil if no error, otherwise it's an error object.
  658. func (client Client) GetBucketVersioning(bucketName string, options ...Option) (GetBucketVersioningResult, error) {
  659. var out GetBucketVersioningResult
  660. params := map[string]interface{}{}
  661. params["versioning"] = nil
  662. resp, err := client.do("GET", bucketName, params, nil, nil, options...)
  663. if err != nil {
  664. return out, err
  665. }
  666. defer resp.Body.Close()
  667. err = xmlUnmarshal(resp.Body, &out)
  668. return out, err
  669. }
  670. // SetBucketEncryption set bucket encryption config
  671. // bucketName the bucket name.
  672. // error it's nil if no error, otherwise it's an error object.
  673. func (client Client) SetBucketEncryption(bucketName string, encryptionRule ServerEncryptionRule, options ...Option) error {
  674. var err error
  675. var bs []byte
  676. bs, err = xml.Marshal(encryptionRule)
  677. if err != nil {
  678. return err
  679. }
  680. buffer := new(bytes.Buffer)
  681. buffer.Write(bs)
  682. contentType := http.DetectContentType(buffer.Bytes())
  683. headers := map[string]string{}
  684. headers[HTTPHeaderContentType] = contentType
  685. params := map[string]interface{}{}
  686. params["encryption"] = nil
  687. resp, err := client.do("PUT", bucketName, params, headers, buffer, options...)
  688. if err != nil {
  689. return err
  690. }
  691. defer resp.Body.Close()
  692. return checkRespCode(resp.StatusCode, []int{http.StatusOK})
  693. }
  694. // GetBucketEncryption get bucket encryption
  695. // bucketName the bucket name.
  696. // error it's nil if no error, otherwise it's an error object.
  697. func (client Client) GetBucketEncryption(bucketName string, options ...Option) (GetBucketEncryptionResult, error) {
  698. var out GetBucketEncryptionResult
  699. params := map[string]interface{}{}
  700. params["encryption"] = nil
  701. resp, err := client.do("GET", bucketName, params, nil, nil, options...)
  702. if err != nil {
  703. return out, err
  704. }
  705. defer resp.Body.Close()
  706. err = xmlUnmarshal(resp.Body, &out)
  707. return out, err
  708. }
  709. // DeleteBucketEncryption delete bucket encryption config
  710. // bucketName the bucket name.
  711. // error it's nil if no error, otherwise it's an error bucket
  712. func (client Client) DeleteBucketEncryption(bucketName string, options ...Option) error {
  713. params := map[string]interface{}{}
  714. params["encryption"] = nil
  715. resp, err := client.do("DELETE", bucketName, params, nil, nil, options...)
  716. if err != nil {
  717. return err
  718. }
  719. defer resp.Body.Close()
  720. return checkRespCode(resp.StatusCode, []int{http.StatusNoContent})
  721. }
  722. //
  723. // SetBucketTagging add tagging to bucket
  724. // bucketName name of bucket
  725. // tagging tagging to be added
  726. // error nil if success, otherwise error
  727. func (client Client) SetBucketTagging(bucketName string, tagging Tagging, options ...Option) error {
  728. var err error
  729. var bs []byte
  730. bs, err = xml.Marshal(tagging)
  731. if err != nil {
  732. return err
  733. }
  734. buffer := new(bytes.Buffer)
  735. buffer.Write(bs)
  736. contentType := http.DetectContentType(buffer.Bytes())
  737. headers := map[string]string{}
  738. headers[HTTPHeaderContentType] = contentType
  739. params := map[string]interface{}{}
  740. params["tagging"] = nil
  741. resp, err := client.do("PUT", bucketName, params, headers, buffer, options...)
  742. if err != nil {
  743. return err
  744. }
  745. defer resp.Body.Close()
  746. return checkRespCode(resp.StatusCode, []int{http.StatusOK})
  747. }
  748. // GetBucketTagging get tagging of the bucket
  749. // bucketName name of bucket
  750. // error nil if success, otherwise error
  751. func (client Client) GetBucketTagging(bucketName string, options ...Option) (GetBucketTaggingResult, error) {
  752. var out GetBucketTaggingResult
  753. params := map[string]interface{}{}
  754. params["tagging"] = nil
  755. resp, err := client.do("GET", bucketName, params, nil, nil, options...)
  756. if err != nil {
  757. return out, err
  758. }
  759. defer resp.Body.Close()
  760. err = xmlUnmarshal(resp.Body, &out)
  761. return out, err
  762. }
  763. //
  764. // DeleteBucketTagging delete bucket tagging
  765. // bucketName name of bucket
  766. // error nil if success, otherwise error
  767. //
  768. func (client Client) DeleteBucketTagging(bucketName string, options ...Option) error {
  769. params := map[string]interface{}{}
  770. params["tagging"] = nil
  771. resp, err := client.do("DELETE", bucketName, params, nil, nil, options...)
  772. if err != nil {
  773. return err
  774. }
  775. defer resp.Body.Close()
  776. return checkRespCode(resp.StatusCode, []int{http.StatusNoContent})
  777. }
  778. // GetBucketStat get bucket stat
  779. // bucketName the bucket name.
  780. // error it's nil if no error, otherwise it's an error object.
  781. func (client Client) GetBucketStat(bucketName string) (GetBucketStatResult, error) {
  782. var out GetBucketStatResult
  783. params := map[string]interface{}{}
  784. params["stat"] = nil
  785. resp, err := client.do("GET", bucketName, params, nil, nil)
  786. if err != nil {
  787. return out, err
  788. }
  789. defer resp.Body.Close()
  790. err = xmlUnmarshal(resp.Body, &out)
  791. return out, err
  792. }
  793. // GetBucketPolicy API operation for Object Storage Service.
  794. //
  795. // Get the policy from the bucket.
  796. //
  797. // bucketName the bucket name.
  798. //
  799. // string return the bucket's policy, and it's only valid when error is nil.
  800. //
  801. // error it's nil if no error, otherwise it's an error object.
  802. //
  803. func (client Client) GetBucketPolicy(bucketName string, options ...Option) (string, error) {
  804. params := map[string]interface{}{}
  805. params["policy"] = nil
  806. resp, err := client.do("GET", bucketName, params, nil, nil, options...)
  807. if err != nil {
  808. return "", err
  809. }
  810. defer resp.Body.Close()
  811. body, err := ioutil.ReadAll(resp.Body)
  812. out := string(body)
  813. return out, err
  814. }
  815. // SetBucketPolicy API operation for Object Storage Service.
  816. //
  817. // Set the policy from the bucket.
  818. //
  819. // bucketName the bucket name.
  820. //
  821. // policy the bucket policy.
  822. //
  823. // error it's nil if no error, otherwise it's an error object.
  824. //
  825. func (client Client) SetBucketPolicy(bucketName string, policy string, options ...Option) error {
  826. params := map[string]interface{}{}
  827. params["policy"] = nil
  828. buffer := strings.NewReader(policy)
  829. resp, err := client.do("PUT", bucketName, params, nil, buffer, options...)
  830. if err != nil {
  831. return err
  832. }
  833. defer resp.Body.Close()
  834. return checkRespCode(resp.StatusCode, []int{http.StatusOK})
  835. }
  836. // DeleteBucketPolicy API operation for Object Storage Service.
  837. //
  838. // Deletes the policy from the bucket.
  839. //
  840. // bucketName the bucket name.
  841. //
  842. // error it's nil if no error, otherwise it's an error object.
  843. //
  844. func (client Client) DeleteBucketPolicy(bucketName string, options ...Option) error {
  845. params := map[string]interface{}{}
  846. params["policy"] = nil
  847. resp, err := client.do("DELETE", bucketName, params, nil, nil, options...)
  848. if err != nil {
  849. return err
  850. }
  851. defer resp.Body.Close()
  852. return checkRespCode(resp.StatusCode, []int{http.StatusNoContent})
  853. }
  854. // SetBucketRequestPayment API operation for Object Storage Service.
  855. //
  856. // Set the requestPayment of bucket
  857. //
  858. // bucketName the bucket name.
  859. //
  860. // paymentConfig the payment configuration
  861. //
  862. // error it's nil if no error, otherwise it's an error object.
  863. //
  864. func (client Client) SetBucketRequestPayment(bucketName string, paymentConfig RequestPaymentConfiguration, options ...Option) error {
  865. params := map[string]interface{}{}
  866. params["requestPayment"] = nil
  867. var bs []byte
  868. bs, err := xml.Marshal(paymentConfig)
  869. if err != nil {
  870. return err
  871. }
  872. buffer := new(bytes.Buffer)
  873. buffer.Write(bs)
  874. contentType := http.DetectContentType(buffer.Bytes())
  875. headers := map[string]string{}
  876. headers[HTTPHeaderContentType] = contentType
  877. resp, err := client.do("PUT", bucketName, params, headers, buffer, options...)
  878. if err != nil {
  879. return err
  880. }
  881. defer resp.Body.Close()
  882. return checkRespCode(resp.StatusCode, []int{http.StatusOK})
  883. }
  884. // GetBucketRequestPayment API operation for Object Storage Service.
  885. //
  886. // Get bucket requestPayment
  887. //
  888. // bucketName the bucket name.
  889. //
  890. // RequestPaymentConfiguration the payment configuration
  891. //
  892. // error it's nil if no error, otherwise it's an error object.
  893. //
  894. func (client Client) GetBucketRequestPayment(bucketName string, options ...Option) (RequestPaymentConfiguration, error) {
  895. var out RequestPaymentConfiguration
  896. params := map[string]interface{}{}
  897. params["requestPayment"] = nil
  898. resp, err := client.do("GET", bucketName, params, nil, nil, options...)
  899. if err != nil {
  900. return out, err
  901. }
  902. defer resp.Body.Close()
  903. err = xmlUnmarshal(resp.Body, &out)
  904. return out, err
  905. }
  906. // GetUserQoSInfo API operation for Object Storage Service.
  907. //
  908. // Get user qos.
  909. //
  910. // UserQoSConfiguration the User Qos and range Information.
  911. //
  912. // error it's nil if no error, otherwise it's an error object.
  913. //
  914. func (client Client) GetUserQoSInfo(options ...Option) (UserQoSConfiguration, error) {
  915. var out UserQoSConfiguration
  916. params := map[string]interface{}{}
  917. params["qosInfo"] = nil
  918. resp, err := client.do("GET", "", params, nil, nil, options...)
  919. if err != nil {
  920. return out, err
  921. }
  922. defer resp.Body.Close()
  923. err = xmlUnmarshal(resp.Body, &out)
  924. return out, err
  925. }
  926. // SetBucketQoSInfo API operation for Object Storage Service.
  927. //
  928. // Set Bucket Qos information.
  929. //
  930. // bucketName tht bucket name.
  931. //
  932. // qosConf the qos configuration.
  933. //
  934. // error it's nil if no error, otherwise it's an error object.
  935. //
  936. func (client Client) SetBucketQoSInfo(bucketName string, qosConf BucketQoSConfiguration, options ...Option) error {
  937. params := map[string]interface{}{}
  938. params["qosInfo"] = nil
  939. var bs []byte
  940. bs, err := xml.Marshal(qosConf)
  941. if err != nil {
  942. return err
  943. }
  944. buffer := new(bytes.Buffer)
  945. buffer.Write(bs)
  946. contentTpye := http.DetectContentType(buffer.Bytes())
  947. headers := map[string]string{}
  948. headers[HTTPHeaderContentType] = contentTpye
  949. resp, err := client.do("PUT", bucketName, params, headers, buffer, options...)
  950. if err != nil {
  951. return err
  952. }
  953. defer resp.Body.Close()
  954. return checkRespCode(resp.StatusCode, []int{http.StatusOK})
  955. }
  956. // GetBucketQosInfo API operation for Object Storage Service.
  957. //
  958. // Get Bucket Qos information.
  959. //
  960. // bucketName tht bucket name.
  961. //
  962. // BucketQoSConfiguration the return qos configuration.
  963. //
  964. // error it's nil if no error, otherwise it's an error object.
  965. //
  966. func (client Client) GetBucketQosInfo(bucketName string, options ...Option) (BucketQoSConfiguration, error) {
  967. var out BucketQoSConfiguration
  968. params := map[string]interface{}{}
  969. params["qosInfo"] = nil
  970. resp, err := client.do("GET", bucketName, params, nil, nil, options...)
  971. if err != nil {
  972. return out, err
  973. }
  974. defer resp.Body.Close()
  975. err = xmlUnmarshal(resp.Body, &out)
  976. return out, err
  977. }
  978. // DeleteBucketQosInfo API operation for Object Storage Service.
  979. //
  980. // Delete Bucket QoS information.
  981. //
  982. // bucketName tht bucket name.
  983. //
  984. // error it's nil if no error, otherwise it's an error object.
  985. //
  986. func (client Client) DeleteBucketQosInfo(bucketName string, options ...Option) error {
  987. params := map[string]interface{}{}
  988. params["qosInfo"] = nil
  989. resp, err := client.do("DELETE", bucketName, params, nil, nil, options...)
  990. if err != nil {
  991. return err
  992. }
  993. defer resp.Body.Close()
  994. return checkRespCode(resp.StatusCode, []int{http.StatusNoContent})
  995. }
  996. // LimitUploadSpeed set upload bandwidth limit speed,default is 0,unlimited
  997. // upSpeed KB/s, 0 is unlimited,default is 0
  998. // error it's nil if success, otherwise failure
  999. func (client Client) LimitUploadSpeed(upSpeed int) error {
  1000. if client.Config == nil {
  1001. return fmt.Errorf("client config is nil")
  1002. }
  1003. return client.Config.LimitUploadSpeed(upSpeed)
  1004. }
  1005. // UseCname sets the flag of using CName. By default it's false.
  1006. //
  1007. // isUseCname true: the endpoint has the CName, false: the endpoint does not have cname. Default is false.
  1008. //
  1009. func UseCname(isUseCname bool) ClientOption {
  1010. return func(client *Client) {
  1011. client.Config.IsCname = isUseCname
  1012. client.Conn.url.Init(client.Config.Endpoint, client.Config.IsCname, client.Config.IsUseProxy)
  1013. }
  1014. }
  1015. // Timeout sets the HTTP timeout in seconds.
  1016. //
  1017. // connectTimeoutSec HTTP timeout in seconds. Default is 10 seconds. 0 means infinite (not recommended)
  1018. // readWriteTimeout HTTP read or write's timeout in seconds. Default is 20 seconds. 0 means infinite.
  1019. //
  1020. func Timeout(connectTimeoutSec, readWriteTimeout int64) ClientOption {
  1021. return func(client *Client) {
  1022. client.Config.HTTPTimeout.ConnectTimeout =
  1023. time.Second * time.Duration(connectTimeoutSec)
  1024. client.Config.HTTPTimeout.ReadWriteTimeout =
  1025. time.Second * time.Duration(readWriteTimeout)
  1026. client.Config.HTTPTimeout.HeaderTimeout =
  1027. time.Second * time.Duration(readWriteTimeout)
  1028. client.Config.HTTPTimeout.IdleConnTimeout =
  1029. time.Second * time.Duration(readWriteTimeout)
  1030. client.Config.HTTPTimeout.LongTimeout =
  1031. time.Second * time.Duration(readWriteTimeout*10)
  1032. }
  1033. }
  1034. // SecurityToken sets the temporary user's SecurityToken.
  1035. //
  1036. // token STS token
  1037. //
  1038. func SecurityToken(token string) ClientOption {
  1039. return func(client *Client) {
  1040. client.Config.SecurityToken = strings.TrimSpace(token)
  1041. }
  1042. }
  1043. // EnableMD5 enables MD5 validation.
  1044. //
  1045. // isEnableMD5 true: enable MD5 validation; false: disable MD5 validation.
  1046. //
  1047. func EnableMD5(isEnableMD5 bool) ClientOption {
  1048. return func(client *Client) {
  1049. client.Config.IsEnableMD5 = isEnableMD5
  1050. }
  1051. }
  1052. // MD5ThresholdCalcInMemory sets the memory usage threshold for computing the MD5, default is 16MB.
  1053. //
  1054. // threshold the memory threshold in bytes. When the uploaded content is more than 16MB, the temp file is used for computing the MD5.
  1055. //
  1056. func MD5ThresholdCalcInMemory(threshold int64) ClientOption {
  1057. return func(client *Client) {
  1058. client.Config.MD5Threshold = threshold
  1059. }
  1060. }
  1061. // EnableCRC enables the CRC checksum. Default is true.
  1062. //
  1063. // isEnableCRC true: enable CRC checksum; false: disable the CRC checksum.
  1064. //
  1065. func EnableCRC(isEnableCRC bool) ClientOption {
  1066. return func(client *Client) {
  1067. client.Config.IsEnableCRC = isEnableCRC
  1068. }
  1069. }
  1070. // UserAgent specifies UserAgent. The default is aliyun-sdk-go/1.2.0 (windows/-/amd64;go1.5.2).
  1071. //
  1072. // userAgent the user agent string.
  1073. //
  1074. func UserAgent(userAgent string) ClientOption {
  1075. return func(client *Client) {
  1076. client.Config.UserAgent = userAgent
  1077. }
  1078. }
  1079. // Proxy sets the proxy (optional). The default is not using proxy.
  1080. //
  1081. // proxyHost the proxy host in the format "host:port". For example, proxy.com:80 .
  1082. //
  1083. func Proxy(proxyHost string) ClientOption {
  1084. return func(client *Client) {
  1085. client.Config.IsUseProxy = true
  1086. client.Config.ProxyHost = proxyHost
  1087. client.Conn.url.Init(client.Config.Endpoint, client.Config.IsCname, client.Config.IsUseProxy)
  1088. }
  1089. }
  1090. // AuthProxy sets the proxy information with user name and password.
  1091. //
  1092. // proxyHost the proxy host in the format "host:port". For example, proxy.com:80 .
  1093. // proxyUser the proxy user name.
  1094. // proxyPassword the proxy password.
  1095. //
  1096. func AuthProxy(proxyHost, proxyUser, proxyPassword string) ClientOption {
  1097. return func(client *Client) {
  1098. client.Config.IsUseProxy = true
  1099. client.Config.ProxyHost = proxyHost
  1100. client.Config.IsAuthProxy = true
  1101. client.Config.ProxyUser = proxyUser
  1102. client.Config.ProxyPassword = proxyPassword
  1103. client.Conn.url.Init(client.Config.Endpoint, client.Config.IsCname, client.Config.IsUseProxy)
  1104. }
  1105. }
  1106. //
  1107. // HTTPClient sets the http.Client in use to the one passed in
  1108. //
  1109. func HTTPClient(HTTPClient *http.Client) ClientOption {
  1110. return func(client *Client) {
  1111. client.HTTPClient = HTTPClient
  1112. }
  1113. }
  1114. //
  1115. // SetLogLevel sets the oss sdk log level
  1116. //
  1117. func SetLogLevel(LogLevel int) ClientOption {
  1118. return func(client *Client) {
  1119. client.Config.LogLevel = LogLevel
  1120. }
  1121. }
  1122. //
  1123. // SetLogger sets the oss sdk logger
  1124. //
  1125. func SetLogger(Logger *log.Logger) ClientOption {
  1126. return func(client *Client) {
  1127. client.Config.Logger = Logger
  1128. }
  1129. }
  1130. //
  1131. // SetAKInterface sets funciton for get the user's ak
  1132. //
  1133. func SetAKInterface(akIf AKInterface) ClientOption {
  1134. return func(client *Client) {
  1135. client.Config.UserAKInf = akIf
  1136. }
  1137. }
  1138. // Private
  1139. func (client Client) do(method, bucketName string, params map[string]interface{},
  1140. headers map[string]string, data io.Reader, options ...Option) (*Response, error) {
  1141. resp, err := client.Conn.Do(method, bucketName, "", params,
  1142. headers, data, 0, nil)
  1143. // get response header
  1144. respHeader, _ := findOption(options, responseHeader, nil)
  1145. if respHeader != nil {
  1146. pRespHeader := respHeader.(*http.Header)
  1147. *pRespHeader = resp.Headers
  1148. }
  1149. return resp, err
  1150. }