diff --git a/.gitignore b/.gitignore index 6d4529c..fd2a409 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,6 @@ cover.out covprofile coverage.html example/CI/media_process/test* +example/CI/workflow_and_job/test* +example/CI/dataindex/test* .vscode diff --git a/bucket.go b/bucket.go index 558f672..4e51f4e 100644 --- a/bucket.go +++ b/bucket.go @@ -150,6 +150,7 @@ type Bucket struct { Name string Region string `xml:"Location,omitempty"` CreationDate string `xml:",omitempty"` + BucketType string `xml:",omitempty"` } type BucketGetObjectVersionsOptions struct { diff --git a/ci_dataindex.go b/ci_dataindex.go new file mode 100644 index 0000000..4fdec46 --- /dev/null +++ b/ci_dataindex.go @@ -0,0 +1,493 @@ +package cos + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "net/http" + "strings" +) + +type Dataset struct { + BindCount int `json:"BindCount"` + CreateTime string `json:"CreateTime"` + DatasetName string `json:"DatasetName"` + Description string `json:"Description"` + FileCount int `json:"FileCount"` + TemplateID string `json:"TemplateId"` + TotalFileSize int `json:"TotalFileSize"` + UpdateTime string `json:"UpdateTime"` +} + +type OptHeaders struct { + XOptionHeader *http.Header `header:"-,omitempty" url:"-" json:"-" xml:"-"` +} + +type CreateDataSetOptions struct { + DatasetName string `json:"DatasetName" url:"-"` + Description string `json:"Description" url:"-"` + TemplateId string `json:"TemplateId" url:"-"` + OptHeaders *OptHeaders `header:"-,omitempty" url:"-" json:"-" xml:"-"` +} + +type CreateDataSetResult struct { + Response struct { + Dataset Dataset `json:"Dataset"` + RequestID string `json:"RequestId"` + } `json:"Response"` +} + +func (s *CIService) baseSend(ctx context.Context, opt interface{}, optionHeader *OptHeaders, uri string, method string) (*bytes.Buffer, *Response, error) { + var buf bytes.Buffer + var f *strings.Reader + var sendOpt *sendOptions + if optionHeader == nil { + optionHeader = &OptHeaders{ + XOptionHeader: &http.Header{}, + } + } + optionHeader.XOptionHeader.Add("Content-Type", "application/json") + optionHeader.XOptionHeader.Add("Accept", "application/json") + if method == http.MethodGet { + sendOpt = &sendOptions{ + baseURL: s.client.BaseURL.CIURL, + uri: uri, + method: method, + optHeader: optionHeader, + optQuery: opt, + result: &buf, + } + } else { + if opt != nil { + bs, err := json.Marshal(opt) + if err != nil { + return nil, nil, err + } + f = strings.NewReader(string(bs)) + } + sendOpt = &sendOptions{ + baseURL: s.client.BaseURL.CIURL, + uri: uri, + method: method, + body: f, + optHeader: optionHeader, + result: &buf, + } + } + resp, err := s.client.send(ctx, sendOpt) + return &buf, resp, err +} + +func (s *CIService) CreateDataSet(ctx context.Context, opt *CreateDataSetOptions) (*CreateDataSetResult, *Response, error) { + var res CreateDataSetResult + if opt == nil { + return nil, nil, fmt.Errorf("opt param nil") + } + buf, resp, err := s.baseSend(ctx, opt, opt.OptHeaders, "/dataset/create", http.MethodPost) + if buf.Len() > 0 { + err = json.Unmarshal(buf.Bytes(), &res) + } + return &res, resp, err +} + +type DescribeDatasetsOptions struct { + MaxResults int64 `url:"maxresults,omitempty" url:"-"` + Prefix string `url:"prefix,omitempty" url:"-"` + Nexttoken string `url:"nexttoken,omitempty" url:"-"` + OptHeaders *OptHeaders `header:"-,omitempty" url:"-" json:"-" xml:"-"` +} +type DescribeDatasetsResult struct { + Response struct { + Datasets []Dataset `json:"Datasets"` + NextToken string `json:"NextToken"` + RequestID string `json:"RequestId"` + } `json:"Response"` +} + +func (s *CIService) DescribeDatasets(ctx context.Context, opt *DescribeDatasetsOptions) (*DescribeDatasetsResult, *Response, error) { + var res DescribeDatasetsResult + if opt == nil { + return nil, nil, fmt.Errorf("opt param nil") + } + buf, resp, err := s.baseSend(ctx, opt, opt.OptHeaders, "/datasets", http.MethodGet) + if buf.Len() > 0 { + err = json.Unmarshal(buf.Bytes(), &res) + } + return &res, resp, err +} + +type UpdateDatasetOptions struct { + DatasetName string `json:"DatasetName" url:"-"` + Description string `json:"Description" url:"-"` + TemplateId string `json:"TemplateId" url:"-"` + OptHeaders *OptHeaders `header:"-,omitempty" url:"-" json:"-" xml:"-"` +} + +type UpdateDatasetResult struct { + Response struct { + Dataset Dataset `json:"Dataset"` + RequestID string `json:"RequestId"` + } `json:"Response"` +} + +func (s *CIService) UpdateDataset(ctx context.Context, opt *UpdateDatasetOptions) (*UpdateDatasetResult, *Response, error) { + var res UpdateDatasetResult + if opt == nil { + return nil, nil, fmt.Errorf("opt param nil") + } + buf, resp, err := s.baseSend(ctx, opt, opt.OptHeaders, "/dataset/update", http.MethodPost) + if buf.Len() > 0 { + err = json.Unmarshal(buf.Bytes(), &res) + } + return &res, resp, err +} + +type DeleteDatasetOptions struct { + DatasetName string `json:"DatasetName" url:"-"` + OptHeaders *OptHeaders `header:"-,omitempty" url:"-" json:"-" xml:"-"` +} + +type DeleteDatasetResult struct { + Response struct { + Dataset Dataset `json:"Dataset"` + RequestID string `json:"RequestId"` + } `json:"Response"` +} + +func (s *CIService) DeleteDataset(ctx context.Context, opt *DeleteDatasetOptions) (*DeleteDatasetResult, *Response, error) { + var res DeleteDatasetResult + if opt == nil { + return nil, nil, fmt.Errorf("opt param nil") + } + buf, resp, err := s.baseSend(ctx, opt, opt.OptHeaders, "/dataset", http.MethodDelete) + if buf.Len() > 0 { + err = json.Unmarshal(buf.Bytes(), &res) + } + return &res, resp, err +} + +type DescribeDatasetOptions struct { + DatasetName string `url:"datasetname,omitempty" url:"-"` + Statistics bool `url:"statistics,omitempty" url:"-"` + OptHeaders *OptHeaders `header:"-,omitempty" url:"-" json:"-" xml:"-"` +} + +type DescribeDatasetResult struct { + Response struct { + Dataset Dataset `json:"Dataset"` + RequestID string `json:"RequestId"` + } `json:"Response"` +} + +func (s *CIService) DescribeDataset(ctx context.Context, opt *DescribeDatasetOptions) (*DescribeDatasetResult, *Response, error) { + var res DescribeDatasetResult + if opt == nil { + return nil, nil, fmt.Errorf("opt param nil") + } + buf, resp, err := s.baseSend(ctx, opt, opt.OptHeaders, "/dataset", http.MethodGet) + if buf.Len() > 0 { + err = json.Unmarshal(buf.Bytes(), &res) + } + return &res, resp, err +} + +type File struct { + URI string `json:"URI,omitempty"` + CustomID string `json:"CustomId,omitempty"` + CustomLabels *map[string]string `json:"CustomLabels,omitempty"` + MediaType string `json:"MediaType,omitempty"` + ContentType string `json:"contenttype,omitempty"` +} + +type CreateFileMetaIndexOptions struct { + DatasetName string `json:"DatasetName,omitempty" url:"-"` + File *File `json:"File,omitempty" url:"-"` + Callback string `json:"Callback,omitempty" url:"-"` + OptHeaders *OptHeaders `header:"-,omitempty" url:"-" json:"-" xml:"-"` +} + +type CreateFileMetaIndexResult struct { + Response struct { + EventID string `json:"EventId"` + RequestID string `json:"RequestId"` + } `json:"Response"` +} + +func (s *CIService) CreateFileMetaIndex(ctx context.Context, opt *CreateFileMetaIndexOptions) (*CreateFileMetaIndexResult, *Response, error) { + var res CreateFileMetaIndexResult + if opt == nil { + return nil, nil, fmt.Errorf("opt param nil") + } + buf, resp, err := s.baseSend(ctx, opt, opt.OptHeaders, "/filemeta/create", http.MethodPost) + if buf.Len() > 0 { + err = json.Unmarshal(buf.Bytes(), &res) + } + return &res, resp, err +} + +type UpdateFileMetaIndexOptions struct { + DatasetName string `json:"DatasetName,omitempty" url:"-"` + File *File `json:"File,omitempty" url:"-"` + Callback string `json:"Callback,omitempty" url:"-"` + OptHeaders *OptHeaders `header:"-,omitempty" url:"-" json:"-" xml:"-"` +} + +type UpdateFileMetaIndexResult struct { + Response struct { + EventID string `json:"EventId"` + RequestID string `json:"RequestId"` + } `json:"Response"` +} + +func (s *CIService) UpdateFileMetaIndex(ctx context.Context, opt *UpdateFileMetaIndexOptions) (*UpdateFileMetaIndexResult, *Response, error) { + var res UpdateFileMetaIndexResult + if opt == nil { + return nil, nil, fmt.Errorf("opt param nil") + } + buf, resp, err := s.baseSend(ctx, opt, opt.OptHeaders, "/filemeta/update", http.MethodPost) + if buf.Len() > 0 { + err = json.Unmarshal(buf.Bytes(), &res) + } + return &res, resp, err +} + +type DescribeFileMetaIndexOptions struct { + DatasetName string `json:"-" url:"datasetname,omitempty"` + Uri string `json:"-" url:"uri,omitempty"` + OptHeaders *OptHeaders `header:"-,omitempty" url:"-" json:"-" xml:"-"` +} + +type FileInfo struct { + DatasetName string `json:"DatasetName,omitempty"` + OwnerID string `json:"OwnerID,omitempty"` + ObjectId string `json:"ObjectId,omitempty"` + CreateTime string `json:"CreateTime,omitempty"` + UpdateTime string `json:"UpdateTime,omitempty"` + URI string `json:"URI,omitempty"` + Filename string `json:"Filename,omitempty"` + MediaType string `json:"MediaType,omitempty"` + ContentType string `json:"ContentType,omitempty"` + COSStorageClass string `json:"COSStorageClass,omitempty"` + Coscrc64 string `json:"COSCRC64,omitempty"` + Size int `json:"Size,omitempty"` + CacheControl string `json:"CacheControl,omitempty"` + ContentDisposition string `json:"ContentDisposition,omitempty"` + ContentEncoding string `json:"ContentEncoding,omitempty"` + ContentLanguage string `json:"ContentLanguage,omitempty"` + ServerSideEncryption string `json:"ServerSideEncryption,omitempty"` + ETag string `json:"ETag,omitempty"` + FileModifiedTime string `json:"FileModifiedTime,omitempty"` + CustomID string `json:"CustomId,omitempty"` + CustomLabels map[string]string `json:"CustomLabels,omitempty"` + COSUserMeta map[string]string `json:"COSUserMeta,omitempty"` + ObjectACL string `json:"ObjectACL",omitempty` + COSTagging map[string]string `json:"COSTagging,omitempty"` +} + +type DescribeFileMetaIndexResult struct { + Response struct { + Files []FileInfo `json:"Files"` + RequestID string `json:"RequestId"` + } `json:"Response"` +} + +func (s *CIService) DescribeFileMetaIndex(ctx context.Context, opt *DescribeFileMetaIndexOptions) (*DescribeFileMetaIndexResult, *Response, error) { + var res DescribeFileMetaIndexResult + if opt == nil { + return nil, nil, fmt.Errorf("opt param nil") + } + buf, resp, err := s.baseSend(ctx, opt, opt.OptHeaders, "/filemeta", http.MethodGet) + if buf.Len() > 0 { + err = json.Unmarshal(buf.Bytes(), &res) + } + return &res, resp, err +} + +type DeleteFileMetaIndexOptions struct { + DatasetName string `url:"-" json:"DatasetName,omitempty"` + Uri string `url:"-" json:"URI,omitempty"` + OptHeaders *OptHeaders `header:"-,omitempty" url:"-" json:"-" xml:"-"` +} + +type DeleteFileMetaIndexResult struct { + Response struct { + RequestID string `json:"RequestId"` + } `json:"Response"` +} + +func (s *CIService) DeleteFileMetaIndex(ctx context.Context, opt *DeleteFileMetaIndexOptions) (*DeleteFileMetaIndexResult, *Response, error) { + var res DeleteFileMetaIndexResult + if opt == nil { + return nil, nil, fmt.Errorf("opt param nil") + } + buf, resp, err := s.baseSend(ctx, opt, opt.OptHeaders, "/filemeta", http.MethodDelete) + if buf.Len() > 0 { + err = json.Unmarshal(buf.Bytes(), &res) + } + return &res, resp, err +} + +type Query struct { + Operation string `json:"Operation,omitempty"` + Field string `json:"Field,omitempty"` + Value string `json:"Value,omitempty"` + SubQueries []*Query `json:"SubQueries,omitempty"` +} + +type Aggregation struct { + Field string `json:"Field,omitempty"` + Operation string `json:"Operation,omitempty"` +} +type DatasetSimpleQueryOptions struct { + DatasetName string `json:"DatasetName,omitempty" url:"-"` + Query *Query `json:"Query,omitempty" url:"-"` + Sort string `json:"Sort,omitempty" url:"-"` + Order string `json:"Order,omitempty" url:"-"` + MaxResults string `json:"MaxResults,omitempty" url:"-"` + Aggregations []*Aggregation `json:"Aggregations,omitempty" url:"-"` + NextToken string `json:"NextToken,omitempty" url:"-"` + WithFields []string `json:"WithFields,omitempty" url:"-"` + OptHeaders *OptHeaders `header:"-,omitempty" url:"-" json:"-" xml:"-"` +} + +type Groups struct { + Count int `json:"Count"` + Value string `json:"Value"` +} +type Aggregations struct { + Field string `json:"Field"` + Groups []Groups `json:"Groups"` + Operation string `json:"Operation"` + Value float32 `json:"Value"` +} + +type DatasetSimpleQueryResult struct { + Response struct { + Aggregations []Aggregations `json:"Aggregations"` + Files []FileInfo `json:"Files"` + NextToken string `json:"NextToken"` + RequestID string `json:"RequestId"` + } `json:"Response"` +} + +func (s *CIService) DatasetSimpleQuery(ctx context.Context, opt *DatasetSimpleQueryOptions) (*DatasetSimpleQueryResult, *Response, error) { + var res DatasetSimpleQueryResult + if opt == nil { + return nil, nil, fmt.Errorf("opt param nil") + } + buf, resp, err := s.baseSend(ctx, opt, opt.OptHeaders, "/datasetquery/simple", http.MethodPost) + if buf.Len() > 0 { + err = json.Unmarshal(buf.Bytes(), &res) + } + return &res, resp, err +} + +type CreateDatasetBindingOptions struct { + DatasetName string `json:"DatasetName,omitempty" url:"-"` + URI string `json:"URI,omitempty" url:"-"` + OptHeaders *OptHeaders `header:"-,omitempty" url:"-" json:"-" xml:"-"` +} + +type Binding struct { + CreateTime string `json:"CreateTime,omitempty" url:"-"` + DatasetName string `json:"DatasetName,omitempty" url:"-"` + Detail string `json:"Detail,omitempty" url:"-"` + State string `json:"State,omitempty" url:"-"` + URI string `json:"URI,omitempty" url:"-"` + UpdateTime string `json:"UpdateTime,omitempty" url:"-"` +} +type CreateDatasetBindingResult struct { + Response struct { + Binding Binding `json:"Binding,omitempty"` + RequestID string `json:"RequestId,omitempty"` + } `json:"Response,omitempty"` +} + +func (s *CIService) CreateDatasetBinding(ctx context.Context, opt *CreateDatasetBindingOptions) (*CreateDatasetBindingResult, *Response, error) { + var res CreateDatasetBindingResult + if opt == nil { + return nil, nil, fmt.Errorf("opt param nil") + } + buf, resp, err := s.baseSend(ctx, opt, opt.OptHeaders, "/datasetbinding/create", http.MethodPost) + if buf.Len() > 0 { + err = json.Unmarshal(buf.Bytes(), &res) + } + return &res, resp, err +} + +type DescribeDatasetBindingOptions struct { + DatasetName string `json:"-" url:"datasetname,omitempty"` + URI string `json:"-" url:"uri,omitempty"` + OptHeaders *OptHeaders `header:"-,omitempty" url:"-" json:"-" xml:"-"` +} + +type DescribeDatasetBindingResult struct { + Response struct { + Binding Binding `json:"Binding,omitempty"` + RequestID string `json:"RequestId,omitempty"` + } `json:"Response,omitempty"` +} + +func (s *CIService) DescribeDatasetBinding(ctx context.Context, opt *DescribeDatasetBindingOptions) (*DescribeDatasetBindingResult, *Response, error) { + var res DescribeDatasetBindingResult + if opt == nil { + return nil, nil, fmt.Errorf("opt param nil") + } + buf, resp, err := s.baseSend(ctx, opt, opt.OptHeaders, "/datasetbinding", http.MethodGet) + if buf.Len() > 0 { + err = json.Unmarshal(buf.Bytes(), &res) + } + return &res, resp, err +} + +type DescribeDatasetBindingsOptions struct { + DatasetName string `json:"-" url:"datasetname,omitempty"` + MaxResults int `json:"-" url:"maxresults,omitempty"` + NextToken string `json:"-" url:"nexttoken,omitempty"` + OptHeaders *OptHeaders `header:"-,omitempty" url:"-" json:"-" xml:"-"` +} + +type DescribeDatasetBindingsResult struct { + Response struct { + Bindings []*Binding `json:"Bindings,omitempty"` + NextToken string `json:"NextToken,omitempty"` + RequestID string `json:"RequestId,omitempty"` + } `json:"Response,omitempty"` +} + +func (s *CIService) DescribeDatasetBindings(ctx context.Context, opt *DescribeDatasetBindingsOptions) (*DescribeDatasetBindingsResult, *Response, error) { + var res DescribeDatasetBindingsResult + if opt == nil { + return nil, nil, fmt.Errorf("opt param nil") + } + buf, resp, err := s.baseSend(ctx, opt, opt.OptHeaders, "/datasetbindings", http.MethodGet) + if buf.Len() > 0 { + err = json.Unmarshal(buf.Bytes(), &res) + } + return &res, resp, err +} + +type DeleteDatasetBindingOptions struct { + DatasetName string `json:"DatasetName,omitempty" url:"-"` + URI string `json:"URI,omitempty" url:"-"` + OptHeaders *OptHeaders `header:"-,omitempty" url:"-" json:"-" xml:"-"` +} + +type DeleteDatasetBindingResult struct { + Response struct { + RequestID string `json:"RequestId"` + } `json:"Response"` +} + +func (s *CIService) DeleteDatasetBinding(ctx context.Context, opt *DeleteDatasetBindingOptions) (*DeleteDatasetBindingResult, *Response, error) { + var res DeleteDatasetBindingResult + if opt == nil { + return nil, nil, fmt.Errorf("opt param nil") + } + buf, resp, err := s.baseSend(ctx, opt, opt.OptHeaders, "/datasetbinding", http.MethodDelete) + if buf.Len() > 0 { + err = json.Unmarshal(buf.Bytes(), &res) + } + return &res, resp, err +} diff --git a/example/CI/dataindex/dataindex.go b/example/CI/dataindex/dataindex.go new file mode 100644 index 0000000..acd62b6 --- /dev/null +++ b/example/CI/dataindex/dataindex.go @@ -0,0 +1,259 @@ +package main + +import ( + "context" + "fmt" + "net/http" + "net/url" + "os" + + "github.com/tencentyun/cos-go-sdk-v5" + "github.com/tencentyun/cos-go-sdk-v5/debug" +) + +func log_status(err error) { + if err == nil { + return + } + if cos.IsNotFoundError(err) { + // WARN + fmt.Println("WARN: Resource is not existed") + } else if e, ok := cos.IsCOSError(err); ok { + fmt.Printf("ERROR: Code: %v\n", e.Code) + fmt.Printf("ERROR: Message: %v\n", e.Message) + fmt.Printf("ERROR: Resource: %v\n", e.Resource) + fmt.Printf("ERROR: RequestId: %v\n", e.RequestID) + // ERROR + } else { + fmt.Printf("ERROR: %v\n", err) + // ERROR + } +} +func getClient() *cos.Client { + u, _ := url.Parse("https://test-125000000.cos.ap-beijing.myqcloud.com") + cu, _ := url.Parse("https://ci.ap-beijing.myqcloud.com") + b := &cos.BaseURL{BucketURL: u, CIURL: cu} + c := cos.NewClient(b, &http.Client{ + Transport: &cos.AuthorizationTransport{ + SecretID: os.Getenv("COS_SECRETID"), + SecretKey: os.Getenv("COS_SECRETKEY"), + Transport: &debug.DebugRequestTransport{ + RequestHeader: true, + // Notice when put a large file and set need the request body, might happend out of memory error. + RequestBody: true, + ResponseHeader: true, + ResponseBody: true, + }, + }, + }) + return c +} + +func CreateDataSet() { + c := getClient() + opt := &cos.CreateDataSetOptions{ + DatasetName: "adataset", + Description: "dataset test", + TemplateId: "Official:COSBasicMeta", + } + res, _, err := c.CI.CreateDataSet(context.Background(), opt) + log_status(err) + fmt.Printf("%+v\n", res) +} + +func DescribeDatasets() { + c := getClient() + opt := &cos.DescribeDatasetsOptions{ + MaxResults: 100, + } + res, _, err := c.CI.DescribeDatasets(context.Background(), opt) + log_status(err) + fmt.Printf("%+v\n", res) +} + +func UpdateDataset() { + c := getClient() + opt := &cos.UpdateDatasetOptions{ + DatasetName: "adataset", + Description: "adataset test", + TemplateId: "Official:COSBasicMeta", + } + res, _, err := c.CI.UpdateDataset(context.Background(), opt) + log_status(err) + fmt.Printf("%+v\n", res) +} + +func DeleteDataset() { + c := getClient() + opt := &cos.DeleteDatasetOptions{ + DatasetName: "adataset", + } + res, _, err := c.CI.DeleteDataset(context.Background(), opt) + log_status(err) + fmt.Printf("%+v\n", res) +} + +func DescribeDataset() { + c := getClient() + opt := &cos.DescribeDatasetOptions{ + DatasetName: "adataset", + Statistics: true, + } + res, _, err := c.CI.DescribeDataset(context.Background(), opt) + log_status(err) + fmt.Printf("%+v\n", res) +} + +func CreateFileMetaIndex() { + c := getClient() + opt := &cos.CreateFileMetaIndexOptions{ + DatasetName: "adataset", + File: &cos.File{ + URI: "cos://test-125000000/12.gif", + CustomID: "123", + CustomLabels: &map[string]string{ + "age": "18", + "level": "18", + }, + MediaType: "image", + ContentType: "image/gif", + }, + } + res, _, err := c.CI.CreateFileMetaIndex(context.Background(), opt) + log_status(err) + fmt.Printf("%+v\n", res) +} + +func UpdateFileMetaIndex() { + c := getClient() + opt := &cos.UpdateFileMetaIndexOptions{ + DatasetName: "adataset", + File: &cos.File{ + URI: "cos://test-125000000/1.gif", + CustomID: "123", + CustomLabels: &map[string]string{ + "age": "18", + "level": "18", + }, + MediaType: "video", + ContentType: "video/gif", + }, + } + res, _, err := c.CI.UpdateFileMetaIndex(context.Background(), opt) + log_status(err) + fmt.Printf("%+v\n", res) +} + +func DescribeFileMetaIndex() { + c := getClient() + opt := &cos.DescribeFileMetaIndexOptions{ + DatasetName: "adataset", + Uri: "cos://test-125000000/1.gif", + } + res, _, err := c.CI.DescribeFileMetaIndex(context.Background(), opt) + log_status(err) + fmt.Printf("%+v\n", res) +} + +func DeleteFileMetaIndex() { + c := getClient() + opt := &cos.DeleteFileMetaIndexOptions{ + DatasetName: "adataset", + Uri: "cos://test-125000000/1.gif", + } + res, _, err := c.CI.DeleteFileMetaIndex(context.Background(), opt) + log_status(err) + fmt.Printf("%+v\n", res) +} + +func DatasetSimpleQuery() { + c := getClient() + opt := &cos.DatasetSimpleQueryOptions{ + DatasetName: "adataset", + Query: &cos.Query{ + Operation: "eq", + Field: "ContentType", + Value: "image/gif", + }, + } + res, _, err := c.CI.DatasetSimpleQuery(context.Background(), opt) + log_status(err) + fmt.Printf("%+v\n", res) +} + +func DatasetSimpleQueryAggregations() { + c := getClient() + opt := &cos.DatasetSimpleQueryOptions{ + DatasetName: "adataset", + Aggregations: []*cos.Aggregation{}, + } + opt.Aggregations = append(opt.Aggregations, &cos.Aggregation{ + Field: "ContentType", + Operation: "group", + }) + res, _, err := c.CI.DatasetSimpleQuery(context.Background(), opt) + log_status(err) + fmt.Printf("%+v\n", res) +} + +func CreateDatasetBinding() { + c := getClient() + opt := &cos.CreateDatasetBindingOptions{ + DatasetName: "adataset", + URI: "cos://test-125000000", + } + res, _, err := c.CI.CreateDatasetBinding(context.Background(), opt) + log_status(err) + fmt.Printf("%+v\n", res) +} + +func DescribeDatasetBinding() { + c := getClient() + opt := &cos.DescribeDatasetBindingOptions{ + DatasetName: "adataset", + URI: "cos://test-125000000", + } + res, _, err := c.CI.DescribeDatasetBinding(context.Background(), opt) + log_status(err) + fmt.Printf("%+v\n", res) +} + +func DescribeDatasetBindings() { + c := getClient() + opt := &cos.DescribeDatasetBindingsOptions{ + DatasetName: "adataset", + // MaxResults: 3, + } + res, _, err := c.CI.DescribeDatasetBindings(context.Background(), opt) + log_status(err) + fmt.Printf("%+v\n", res) +} + +func DeleteDatasetBinding() { + c := getClient() + opt := &cos.DeleteDatasetBindingOptions{ + DatasetName: "adataset", + URI: "cos://test-125000000", + } + res, _, err := c.CI.DeleteDatasetBinding(context.Background(), opt) + log_status(err) + fmt.Printf("%+v\n", res) +} + +func main() { + // CreateDataSet() + // DescribeDatasets() + // UpdateDataset() + // DeleteDataset() + // DescribeDataset() + // CreateFileMetaIndex() + // UpdateFileMetaIndex() + // DescribeFileMetaIndex() + // DeleteFileMetaIndex() + // DatasetSimpleQuery() + // DatasetSimpleQueryAggregations() + // CreateDatasetBinding() + // DescribeDatasetBinding() + // DescribeDatasetBindings() + // DeleteDatasetBinding() +} diff --git a/service.go b/service.go index c31e976..483af72 100644 --- a/service.go +++ b/service.go @@ -26,6 +26,7 @@ type ServiceGetOptions struct { Marker string `url:"marker,omitempty"` Range string `url:"range,omitempty"` CreateTime int64 `url:"create-time,omitempty"` + Region string `url:"region,omitempty"` } // Get Service 接口实现获取该用户下所有Bucket列表。