client.go 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  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, options ...Option) error {
  155. params := map[string]interface{}{}
  156. resp, err := client.do("DELETE", bucketName, params, nil, nil, options...)
  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, options ...Option) (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, options...)
  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. // SetAKInterface sets funciton for get the user's ak
  1131. //
  1132. func SetCredentialsProvider(provider CredentialsProvider) ClientOption {
  1133. return func(client *Client) {
  1134. client.Config.CredentialsProvider = provider
  1135. }
  1136. }
  1137. // Private
  1138. func (client Client) do(method, bucketName string, params map[string]interface{},
  1139. headers map[string]string, data io.Reader, options ...Option) (*Response, error) {
  1140. resp, err := client.Conn.Do(method, bucketName, "", params, headers, data, 0, nil)
  1141. // get response header
  1142. respHeader, _ := findOption(options, responseHeader, nil)
  1143. if respHeader != nil {
  1144. pRespHeader := respHeader.(*http.Header)
  1145. *pRespHeader = resp.Headers
  1146. }
  1147. return resp, err
  1148. }