package
0.0.0-20181024121726-20aadb4988d5
Repository: https://github.com/techcatslab/apix.git
Documentation: pkg.go.dev

# README

Usage

import "github.com/TechCatsLab/apix/cloud/tencent/tcos"

AuthorizationConfig

Get APPID, SecretID, SecretKey from https://console.cloud.tencent.com/cam/capi

var authorizationConfig = &tcos.AuthorizationConfig{
    AppID:     YourAPPID,
    SecretID:  YourSecretID,
    SecretKey: YourSecretKey,
}

GetServiceClient

authorizationClient, err := tcos.CreateAuthorizationClient(authorizationConfig)

buckets, err := authorizationClient.ListBuckets()
for _, bucket := range buckets {
    fmt.Printf("Bucket: %+v\n", bucket)
}

GetBucketClient

  • put new bucket
bucketConfig := &tcos.BucketConfig{{
    AuthorizationConfig: authorizationConfig,
    Name:                NewBucketName,
    Region:              Region(e.g. "ap-shanghai"),
}

bucketClient, err := tcos.PutBucket(config, nil)
  • from authorizationClient
buckets, err := authorizationClient.ListBuckets()

bucketClient, err := authorizationClient.CreateBucketClient(&buckets[0])
  • from CreateBucketClient
bucketConfig := &tcos.BucketConfig{{
    AuthorizationConfig: authorizationConfig,
    Name:                BucketName,
    Region:              Region(e.g. "ap-shanghai"),
}

bucketClient, err := tcos.CreateBucketClient(bucketConfig)

BucketClient Operations

  • PutCORS(opt *tcos.BucketPutCORSOptions)
opt := &tcos.BucketPutCORSOptions{
    Rules: []tcos.BucketCORSRule{
        {
            AllowedOrigins: []string{"http://www.qq.com"},
            AllowedMethods: []string{"PUT", "GET"},
            AllowedHeaders: []string{"x-cos-meta-test", "x-cos-xx"},
            MaxAgeSeconds:  500,
            ExposeHeaders:  []string{"x-cos-meta-test1"},
        },
        {
            ID:             "1234",
            AllowedOrigins: []string{"http://www.google.com", "twitter.com"},
            AllowedMethods: []string{"PUT", "GET"},
            MaxAgeSeconds:  500,
        },
    },
}
err = bucketClient.PutCORS(opt)
  • GetCORS()
rules, err := bucketClient.GetCORS()
for _, r := range rules {
    fmt.Printf("%+v\n", r)
}
  • PutObject(objectKey string, reader io.Reader, force bool, opt *ObjectPutOptions)
f, err := os.Open(filename)
s, err := f.Stat()

opt := &ObjectPutOptions{
    ObjectPutHeaderOptions: &ObjectPutHeaderOptions{
        ContentLength: int(s.Size()),
    },
}
resp, err = bucketClient.PutObject(s.Name(), f, false, opt)
  • GetObject(objectKey string, opt *ObjectGetOptions)
resp, err := bucketClient.GetObject(objectKey, nil)
data, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
err = ioutil.WriteFile(filepath.Join(localPath, filename), data, 0666)
  • Copy(sourceKey, destKey string, force bool, opt *ObjectCopyOptions)
res, resp, err = bucketClient.Copy("filename_1", "files/filename_1", true, nil)
  • Move(sourceKey, destKey string, force bool, opt *ObjectCopyOptions)
res, resp, err = bucketClient.Move("filename_1", "files/filename_1", true, nil)
  • Rename(sourceKey, fileName string, opt *ObjectCopyOptions)
res, resp, err = bucketClient.Rename("filename_1", "filename_2", true, nil)
  • DeleteObject(objectKey string)
err = bucketClient.DeleteObject(filename)
  • ListObjects(opt *BucketGetOptions)
list, err := bucketClient.ListObjects(nil)
for _, obj := range list {
    t.Logf("Object: %+v\n", obj)
}
  • ObjectDownloadURL(objectKey string)
url, err := bucketClient.ObjectDownloadURL(objectKey)
  • ObjectStaticURL(objectKey string) - NOTICE: This action need enable static website in basicconfig of bucket
url, err := bucketClient.ObjectStaticURL(objectKey)
  • HeadObject(objectKey string, opt *ObjectHeadOptions)
resp, err = bucketClient.HeadObject(filename, nil)

# Functions

CheckAuthorizationConfig ...
ConfirmAuthorization is used to confirm authorization info.
Copy ...
CreateAuthorizationClient creates a service client.
CreateBucketClient creates a bucket client, which can request bucket operations.
DownloadToLocal object to local.
ErrConvert to OpError.
HeadBucket tests bucket is available or not Status: 200 - ok, 403 - Forbidden, 404 - Not Found.
PutBucket is used to create a new bucket.

# Structs

AuthorizationClient is used for services.
AuthorizationConfig contains AppID, SecretID, SecretKey.
BucketClient is used for bucket operation.
BucketConfig contains AuthorizationConfig, Name, Region.
OpError contains code & message, which describes the Err.

# Type aliases

ACLHeaderOptions see Permission-related headers in https://intl.cloud.tencent.com/document/product/436/7749#non-common-header.
Bucket contains Name, AppID, Region, CreateDate of created bucket.
BucketCORSRule : ID string `xml:"ID,omitempty"` AllowedMethods []string `xml:"AllowedMethod"` AllowedOrigins []string `xml:"AllowedOrigin"` AllowedHeaders []string `xml:"AllowedHeader,omitempty"` MaxAgeSeconds int `xml:"MaxAgeSeconds,omitempty"` ExposeHeaders []string `xml:"ExposeHeader,omitempty"`.
BucketGetOptions contains request parameters of ListObjects() see options details in https://intl.cloud.tencent.com/document/product/436/7734#request-parameters.
BucketPutCORSOptions contains XMLName and BucketCORSRule details see https://intl.cloud.tencent.com/document/product/436/8279#request-body.
BucketPutOptions in https://intl.cloud.tencent.com/document/product/436/7738#request-header.
Object contains Key, ETag, Size, PartNumber, LastModified, StorageClass, Owner of created object e.g.
ObjectCopyHeaderOptions see https://cloud.tencent.com/document/product/436/10881#.E9.9D.9E.E5.85.AC.E5.85.B1.E5.A4.B4.E9.83.A8.
ObjectCopyOptions contains ObjectCopyHeaderOptions and ACLHeaderOptions.
ObjectCopyResult ...
ObjectGetOptions is used for GetObject() details see https://intl.cloud.tencent.com/document/product/436/7753.
ObjectHeadOptions specified "IfModifiedSince" Header.
ObjectPutHeaderOptions see Recommended Header in https://intl.cloud.tencent.com/document/product/436/7749#non-common-header.
ObjectPutOptions contains ACLHeaderOptions and ObjectPutHeaderOptions details see https://intl.cloud.tencent.com/document/product/436/7749#request-header.