-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
594 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package qiniu | ||
|
||
import ( | ||
"github.com/eleven26/goss/core" | ||
"github.com/qiniu/go-sdk/v7/storage" | ||
) | ||
|
||
type Chunks struct { | ||
bucket string | ||
prefix string | ||
bucketManager *storage.BucketManager | ||
|
||
nextMarker string | ||
} | ||
|
||
func NewChunks(bucket string, prefix string, bucketManager *storage.BucketManager) core.Chunks { | ||
return &Chunks{ | ||
bucket: bucket, | ||
prefix: prefix, | ||
bucketManager: bucketManager, | ||
} | ||
} | ||
|
||
func (c *Chunks) Chunk() (*core.ListObjectResult, error) { | ||
// 参考文档:https://developer.qiniu.com/kodo/1284/list | ||
// ListFiles 最后一个参数 limit 为单次列举的条目数,范围为1-1000。 默认值为1000。 | ||
entries, _, nextMarker, hasNext, err := c.bucketManager.ListFiles(c.bucket, c.prefix, "", c.nextMarker, 100) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
c.nextMarker = nextMarker | ||
|
||
return NewListObjectResult(entries, hasNext), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package qiniu | ||
|
||
import "github.com/spf13/viper" | ||
|
||
type config struct { | ||
Bucket string | ||
AccessKey string | ||
SecretKey string | ||
Zone string | ||
Domain string | ||
Private bool | ||
} | ||
|
||
func getConfig(viper *viper.Viper) *config { | ||
return &config{ | ||
Bucket: viper.GetString("qiniu.bucket"), | ||
AccessKey: viper.GetString("qiniu.access_key"), | ||
SecretKey: viper.GetString("qiniu.secret_key"), | ||
Zone: viper.GetString("qiniu.zone"), | ||
Domain: viper.GetString("qiniu.domain"), | ||
Private: viper.GetBool("qiniu.private"), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package qiniu | ||
|
||
import ( | ||
"github.com/eleven26/goss/core" | ||
"github.com/qiniu/go-sdk/v7/auth/qbox" | ||
"github.com/qiniu/go-sdk/v7/storage" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
type Driver struct { | ||
Viper *viper.Viper | ||
} | ||
|
||
func NewDriver(opts ...core.Option) core.Driver { | ||
driver := &Driver{} | ||
|
||
for _, option := range opts { | ||
option(driver) | ||
} | ||
|
||
return driver | ||
} | ||
|
||
func (d *Driver) Storage() (core.Storage, error) { | ||
conf := getConfig(d.Viper) | ||
|
||
if conf.Bucket == "" || conf.AccessKey == "" || conf.SecretKey == "" { | ||
return nil, core.ErrorConfigEmpty | ||
} | ||
|
||
mac := qbox.NewMac(conf.AccessKey, conf.SecretKey) | ||
cfg := storage.Config{ | ||
UseHTTPS: true, | ||
} | ||
|
||
store := Store{ | ||
config: *conf, | ||
bucketManager: storage.NewBucketManager(mac, &cfg), | ||
} | ||
|
||
return core.NewStorage(&store), nil | ||
} | ||
|
||
func (d Driver) Name() string { | ||
return "qiniu" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package qiniu | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
|
||
"github.com/qiniu/go-sdk/v7/storage" | ||
) | ||
|
||
type File struct { | ||
item storage.ListItem | ||
} | ||
|
||
func (f *File) Key() string { | ||
return f.item.Key | ||
} | ||
|
||
func (f *File) Type() string { | ||
return strconv.Itoa(f.item.Type) | ||
} | ||
|
||
func (f *File) Size() int64 { | ||
return f.item.Fsize | ||
} | ||
|
||
func (f *File) ETag() string { | ||
return f.item.Hash | ||
} | ||
|
||
func (f *File) LastModified() time.Time { | ||
return time.UnixMicro(f.item.PutTime / 10) | ||
} |
Oops, something went wrong.