Skip to content
This repository has been archived by the owner on Apr 1, 2022. It is now read-only.

Commit

Permalink
修改配置传入的方式
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonken committed Mar 15, 2018
1 parent 1f2ab50 commit 6c98642
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cos/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestBucket_UploadObjectBySlice(t *testing.T) {
ctx := GetTimeoutCtx(time.Second * 30)
dst := "testfile_slice"
src := "testfiles/test.zip"
err := client.Bucket(bu).UploadObjectBySlice(ctx, dst, src, 3)
err := client.Bucket(bu).UploadObjectBySlice(ctx, dst, src, 3, nil)
if err != nil {
t.Error(err)
}
Expand Down
10 changes: 5 additions & 5 deletions cos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ type Client struct {
}

// New cos包的入口
func New(appID, secretID, secretKey, region string) *Client {
func New(o *Option) *Client {
client := Client{}
conf := getDefaultConf()
conf.AppID = appID
conf.SecretID = secretID
conf.SecretKey = secretKey
conf.Region = region
conf.AppID = o.AppID
conf.SecretID = o.SecretID
conf.SecretKey = o.SecretKey
conf.Region = o.Region

conn := Conn{&http.Client{}, conf}
client.conn = &conn
Expand Down
8 changes: 8 additions & 0 deletions cos/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package cos

type Option struct {
AppID string `mapstructure:"app_id" json:"app_id"`
SecretID string `mapstructure:"secret_id" json:"secret_id"`
SecretKey string `mapstructure:"secret_key" json:"secret_key"`
Region string `mapstructure:"region" json:"region"`
}
2 changes: 1 addition & 1 deletion cos/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (
)

func setUp() {
client = New("1254217795", "AKIDkOq6C6qLgstiMqmGF2d3HKBpHYeZlpAH", "Rny65tVv9BQuHUVKxOehZFqJbifYN7g3", "ap-chengdu")
client = New(&Option{"1254217795", "AKIDkOq6C6qLgstiMqmGF2d3HKBpHYeZlpAH", "Rny65tVv9BQuHUVKxOehZFqJbifYN7g3", "ap-chengdu"})
}

func assert(want, condition, got interface{}) {
Expand Down

0 comments on commit 6c98642

Please sign in to comment.