Skip to content

Commit

Permalink
Merge pull request #4 from paradeum-team/yuan
Browse files Browse the repository at this point in the history
update sdk code
  • Loading branch information
freedomiris authored May 20, 2023
2 parents 078eb91 + 53c8d56 commit 86a7664
Show file tree
Hide file tree
Showing 34 changed files with 5,879 additions and 516 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/logs/
/bin
/temp
/tmp
*.log
VERSION
runtime
Binary file modified chainstorage-sdk
Binary file not shown.
4 changes: 2 additions & 2 deletions chainstorage-sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ server:
chainStorageApiToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcGlLZXkiOiJaT0dKNVI0QTZPU1JIWUlOTUlMQSIsImV4cCI6MTY4NDgzNDUxNSwiaWRlbnRpdHkiOnsiSWQiOjYsIk5pY2tOYW1lIjoidXNlcjEiLCJQcm9maWxlSW1hZ2UiOiIiLCJXYWxsZXRBZGRyIjoidXNlcjEiLCJ0ZXJtaW5hbCI6InBjL3NkayJ9LCJvcmlnX2lhdCI6MTY4MjI0MjUyNH0.w0lQ-RGufy5j3yMfbnL94hOvLeeCSccZbSIwd6kXvbI
#HTTP request user agent (K2请求需要)
httpRequestUserAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
#HTTP request user agent (K2请求需要)
httpRequestOvertime: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
#HTTP request overtime
httpRequestOvertime: 30

logger:
logPath: ./logs
Expand Down
22 changes: 22 additions & 0 deletions chainstoragesdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
../.idea/
*.iml
*.yaml
*/*.iml
*.ipr
*/*.ipr
*.iws
*/*.iws
*/*.log
*/target/
*.DS_Store
.DS_Store
/.DS_Store
*.project
*/data/
*/logs/
/bin
/temp
/tmp
*.log
VERSION
runtime
50 changes: 44 additions & 6 deletions chainstoragesdk/bucket.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package chainstoragesdk

import (
"chainstorage-sdk/chainstoragesdk/code"
"chainstorage-sdk/chainstoragesdk/consts"
"chainstorage-sdk/chainstoragesdk/model"
"encoding/json"
"errors"
"fmt"
"github.com/kataras/golog"
"github.com/paradeum-team/chainstorage-sdk/code"
"github.com/paradeum-team/chainstorage-sdk/consts"
"github.com/paradeum-team/chainstorage-sdk/model"
"github.com/ulule/deepcopier"
"net/http"
"net/url"
Expand Down Expand Up @@ -48,7 +48,7 @@ func (b *Bucket) GetBucketList(bucketName string, pageSize, pageIndex int) (mode
// 请求Url
urlQuery = strings.TrimSuffix(urlQuery, "&")

//apiBaseAddress := conf.myConfig.ChainStorageApiBaseAddress
//apiBaseAddress := conf.cssConfig.ChainStorageApiBaseAddress
apiBaseAddress := b.Config.ChainStorageApiBaseAddress
apiPath := "api/v1/buckets"
apiUrl := fmt.Sprintf("%s%s", apiBaseAddress, apiPath)
Expand Down Expand Up @@ -143,7 +143,7 @@ func (b *Bucket) EmptyBucket(bucketId int) (model.BucketEmptyResponse, error) {

// 参数设置
if bucketId <= 0 {
return response, errors.New("请输入正确的桶ID.")
return response, code.ErrInvalidBucketId
}

params := map[string]interface{}{
Expand Down Expand Up @@ -186,7 +186,7 @@ func (b *Bucket) RemoveBucket(bucketId int, autoEmptyBucketData bool) (model.Buc

// 参数设置
if bucketId <= 0 {
return response, errors.New("请输入正确的桶ID.")
return response, code.ErrInvalidBucketId
}

// 自动清空数据
Expand Down Expand Up @@ -228,6 +228,44 @@ func (b *Bucket) RemoveBucket(bucketId int, autoEmptyBucketData bool) (model.Buc
return response, nil
}

// 根据桶名称获取桶数据
func (b *Bucket) GetBucketByName(bucketName string) (model.BucketCreateResponse, error) {
response := model.BucketCreateResponse{}

// 参数设置
if err := checkBucketName(bucketName); err != nil {
return response, err
}

apiBaseAddress := b.Config.ChainStorageApiBaseAddress
apiPath := fmt.Sprintf("api/v1/bucket/name/%s", url.QueryEscape(bucketName))
apiUrl := fmt.Sprintf("%s%s", apiBaseAddress, apiPath)

// API调用
httpStatus, body, err := b.Client.RestyGet(apiUrl)
if err != nil {
b.logger.Errorf(fmt.Sprintf("API:GetBucketByName:HttpGet, apiUrl:%s, httpStatus:%d, err:%+v\n", apiUrl, httpStatus, err))

return response, err
}

if httpStatus != http.StatusOK {
b.logger.Errorf(fmt.Sprintf("API:GetBucketByName:HttpGet, apiUrl:%s, httpStatus:%d, body:%s\n", apiUrl, httpStatus, string(body)))

return response, errors.New(string(body))
}

// 响应数据解析
err = json.Unmarshal(body, &response)
if err != nil {
b.logger.Errorf(fmt.Sprintf("API:GetBucketByName:JsonUnmarshal, body:%s, err:%+v\n", string(body), err))

return response, err
}

return response, nil
}

// endregion 桶数据

// 检查桶名称
Expand Down
212 changes: 0 additions & 212 deletions chainstoragesdk/bucket_test.go

This file was deleted.

Loading

0 comments on commit 86a7664

Please sign in to comment.