Exemple #1
0
/**
*函数原型:func (client *Client) ListBuckets() (requst *models.Result, listBucketOutPut *models.ListBucketsOutput)
*函数功能:获取桶列表
*参数说明:
*返回值:requst: Resul对象实例
*	   listBucketOutPut:ListBucketsOutput对象实例
 */
func (client *Client) ListBuckets() (requst *models.Result, listBucketOutPut *models.ListBucketsOutput) {
	requst = &models.Result{}
	util := utils.NewUtil(client.AK, client.SK, client.Endpoint, client.PathStyle)
	err := util.InitConect("GET", "", "", nil)
	if err != nil {
		requst.Err = err
		return requst, nil
	}
	Response, requst := util.DoExec()
	if requst.Err != nil {
		return requst, nil
	}
	xml, err := ioutil.ReadAll(Response.Body)
	if err != nil {
		requst.Err = err
		return requst, nil
	}
	util.Close()
	listBucketOutPut = &models.ListBucketsOutput{}
	err = utils.PareseXML(xml, listBucketOutPut)
	if err != nil {
		requst.Err = err
		return requst, nil
	}
	return requst, listBucketOutPut
}
Exemple #2
0
/**
*函数原型:func (client *Client) GetBucketStorageInfo(bucketName string) (requst *models.Result, getBucketStorageInfoOutput *models.GetBucketStorageInfoOutput)
*函数功能:获取桶的存储信息
*参数说明:bucketName:桶名
*返回值:requst: Resul对象实例
*	   getBucketStorageInfoOutput:GetBucketStorageInfoOutput对象实例
 */
func (client *Client) GetBucketStorageInfo(bucketName string) (requst *models.Result, getBucketStorageInfoOutput *models.GetBucketStorageInfoOutput) {
	requst = &models.Result{}
	if bucketName == "" {
		requst.Err = errors.New(models.BUCKET_NIL)
		return requst, nil
	}
	util := utils.NewUtil(client.AK, client.SK, client.Endpoint, client.PathStyle)
	util.SetPath("storageinfo", "")

	err := util.InitConect("GET", bucketName, "", nil)
	if err != nil {
		requst.Err = err
		return requst, nil
	}
	Response, requst := util.DoExec()
	if requst.Err != nil {
		return requst, nil
	}
	xml, err := ioutil.ReadAll(Response.Body)
	if err != nil {
		requst.Err = err
		return requst, nil
	}
	util.Close()
	getBucketStorageInfoOutput = &models.GetBucketStorageInfoOutput{}
	err = utils.PareseXML(xml, getBucketStorageInfoOutput)
	if err != nil {
		requst.Err = err
		return requst, nil
	}
	return requst, getBucketStorageInfoOutput
}
Exemple #3
0
/**
*函数原型:func (client *Client) ListObjects(input *models.ListObjectsInput) (requst *models.Result, listObjectsOutput *models.ListObjectsOutput)
*函数功能:获取桶内对象
*参数说明:bucketName:桶名
*返回值:requst: Resul对象实例
*		listObjectsOutput:ListObjectsOutput对象实例
 */
func (client *Client) ListObjects(input *models.ListObjectsInput) (requst *models.Result, listObjectsOutput *models.ListObjectsOutput) {
	requst = &models.Result{}
	if input.Bucket == "" {
		requst.Err = errors.New(models.BUCKET_NIL)
		return requst, nil
	}
	util := utils.NewUtil(client.AK, client.SK, client.Endpoint, client.PathStyle)
	if input.Prefix != "" {
		util.SetPath("prefix", input.Prefix)
	}
	if input.Marker != "" {
		util.SetPath("marker", input.Marker)
	}
	if input.MaxKeys != 0 {
		util.SetPath("max-keys", strconv.Itoa(input.MaxKeys))
	}
	if input.Delimiter != "" {
		util.SetPath("delimiter", input.Delimiter)
	}
	err := util.InitConect("GET", input.Bucket, "", nil)
	if err != nil {
		requst.Err = err
		return requst, nil
	}
	Response, requst := util.DoExec()
	if requst.Err != nil {
		return requst, nil
	}
	xml, err := ioutil.ReadAll(Response.Body)
	if err != nil {
		requst.Err = err
		return requst, nil
	}
	util.Close()
	listObjectsOutput = &models.ListObjectsOutput{}
	err = utils.PareseXML(xml, listObjectsOutput)
	if err != nil {
		requst.Err = err
		return requst, nil
	}
	return requst, listObjectsOutput
}
Exemple #4
0
/**
*函数原型:func (client *Client) DeleteObjects(input *models.DeleteObjectsInput) (requst *models.Result, deleteObjectsOutput *models.DeleteObjectsOutput)
*函数功能:删除对象列表
*参数说明:input:DeleteObjectsInput对象实例
*返回值:requst: Resul对象实例
*		deleteObjectsOutput:DeleteObjectsOutput对象实例
 */
func (client *Client) DeleteObjects(input *models.DeleteObjectsInput) (requst *models.Result, deleteObjectsOutput *models.DeleteObjectsOutput) {
	requst = &models.Result{}
	if input.Bucket == "" {
		requst.Err = errors.New(models.BUCKET_NIL)
		return requst, nil
	}
	util := utils.NewUtil(client.AK, client.SK, client.Endpoint, client.PathStyle)
	xml := utils.DeleteObjectsXML(input)
	ioRead := strings.NewReader(xml)

	util.SetPath("delete", "")
	err := util.InitConect("POST", input.Bucket, "", ioRead)
	if err != nil {
		requst.Err = err
		return requst, nil
	}
	util.SetHeader("Content-Length", strconv.Itoa(len(xml)))
	util.SetHeader("Content-MD5", utils.HashMD5([]byte(xml)))
	Response, requst := util.DoExec()
	if requst.Err != nil {
		return requst, nil
	}

	deleteObjectsOutput = &models.DeleteObjectsOutput{}
	RspXML, err := ioutil.ReadAll(Response.Body)
	util.Close()
	if err != nil {
		requst.Err = err
		return requst, nil
	}
	err = utils.PareseXML(RspXML, deleteObjectsOutput)
	if err != nil {
		requst.Err = err
		return requst, nil
	}
	return requst, deleteObjectsOutput
}