Skip to content

Commit a45a9f4

Browse files
committed
refactor: rename Qiniu to Client for consistency and clarity
Signed-off-by: tbxark <[email protected]>
1 parent 48fa876 commit a45a9f4

File tree

6 files changed

+31
-31
lines changed

6 files changed

+31
-31
lines changed

layout/cmd/app/wire_gen.go

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

layout/cmd/cli/storage/cmd/migrate.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
// migrateCmd represents the cdn command
2020
var migrateCmd = &cobra.Command{
2121
Use: "migrate",
22-
Short: "Qiniu migration Tools",
22+
Short: "Client migration Tools",
2323
Long: `Move files from one qiniu bucket to another bucket.`,
2424
Run: runMigrate,
2525
}
@@ -48,7 +48,7 @@ func runMigrate(cmd *cobra.Command, args []string) {
4848
if err != nil {
4949
log.Panicf("load config error: %v", err)
5050
}
51-
upload := qiniu.NewQiniu(cfg.Storage)
51+
upload := qiniu.NewClient(cfg.Storage)
5252
list := strings.Split(string(file), "\n")
5353
ctx := context.Background()
5454
result := make(map[string]string, len(list))

layout/cmd/cli/storage/cmd/upload.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
var uploadCmd = &cobra.Command{
1919
Use: "upload",
2020
Short: "Upload files to storage",
21-
Long: `Upload files to Qiniu storage.`,
21+
Long: `Upload files to Client storage.`,
2222
Run: runUpload,
2323
}
2424

@@ -41,7 +41,7 @@ func runUpload(cmd *cobra.Command, args []string) {
4141
log.Panicf("load config error: %v", err)
4242
}
4343

44-
upload := qiniu.NewQiniu(cfg.Storage)
44+
upload := qiniu.NewClient(cfg.Storage)
4545
ctx := context.Background()
4646
resBuf := strings.Builder{}
4747
nameBuilder := storage.KeepFileNameKeyBuilder()

layout/internal/wire.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ var cacheSet = wire.NewSet(
2020
)
2121

2222
var storageSet = wire.NewSet(
23-
qiniu.NewQiniu,
24-
wire.Bind(new(storage.Storage), new(*qiniu.Qiniu)),
23+
qiniu.NewClient,
24+
wire.Bind(new(storage.Storage), new(*qiniu.Client)),
2525
)
2626

2727
var ProviderSet = wire.NewSet(

storage/qiniu/qiniu.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,26 @@ type Config struct {
2828
Host string `json:"host" yaml:"host"`
2929
}
3030

31-
type Qiniu struct {
31+
type Client struct {
3232
mac *qbox.Mac
3333
config *Config
3434
}
3535

36-
func NewQiniu(config *Config) *Qiniu {
36+
func NewClient(config *Config) *Client {
3737
config.Domain = strings.TrimSuffix(config.Domain, "/")
3838
if config.Host == "" {
3939
u, err := url.Parse(config.Domain)
4040
if err == nil {
4141
config.Host = u.Host
4242
}
4343
}
44-
return &Qiniu{
44+
return &Client{
4545
mac: qbox.NewMac(config.AccessKey, config.SecretKey),
4646
config: config,
4747
}
4848
}
4949

50-
func (n *Qiniu) GenerateURL(key string) string {
50+
func (n *Client) GenerateURL(key string) string {
5151
if key == "" {
5252
return ""
5353
}
@@ -61,7 +61,7 @@ func (n *Qiniu) GenerateURL(key string) string {
6161
return buf.String()
6262
}
6363

64-
func (n *Qiniu) GenerateImageURL(key string, width int) string {
64+
func (n *Client) GenerateImageURL(key string, width int) string {
6565
// 判断是不是已经拼接了 ?imageView2 参数
6666
if strings.Contains(key, "?imageView2") {
6767
// 从URL中提取key
@@ -73,15 +73,15 @@ func (n *Qiniu) GenerateImageURL(key string, width int) string {
7373
return n.GenerateURL(key) + "?imageView2/2/w/" + strconv.Itoa(width) + "/q/75"
7474
}
7575

76-
func (n *Qiniu) GenerateURLs(keys []string) []string {
76+
func (n *Client) GenerateURLs(keys []string) []string {
7777
urls := make([]string, len(keys))
7878
for i, key := range keys {
7979
urls[i] = n.GenerateURL(key)
8080
}
8181
return urls
8282
}
8383

84-
func (n *Qiniu) ExtractKeyFromURLWithMode(uri string, strict bool) (string, error) {
84+
func (n *Client) ExtractKeyFromURLWithMode(uri string, strict bool) (string, error) {
8585
if uri == "" {
8686
return "", nil
8787
}
@@ -104,12 +104,12 @@ func (n *Qiniu) ExtractKeyFromURLWithMode(uri string, strict bool) (string, erro
104104
return strings.TrimPrefix(u.Path, "/"), nil
105105
}
106106

107-
func (n *Qiniu) ExtractKeyFromURL(uri string) string {
107+
func (n *Client) ExtractKeyFromURL(uri string) string {
108108
key, _ := n.ExtractKeyFromURLWithMode(uri, true)
109109
return key
110110
}
111111

112-
func (n *Qiniu) GenerateUploadToken(fileName string, dir string, nameBuilder func(fileName string, dir ...string) string) models.FileUploadToken {
112+
func (n *Client) GenerateUploadToken(fileName string, dir string, nameBuilder func(fileName string, dir ...string) string) models.FileUploadToken {
113113
fileExt := path.Ext(fileName)
114114
sum := md5.Sum([]byte(fileName))
115115
nameMd5 := hex.EncodeToString(sum[:])
@@ -127,7 +127,7 @@ func (n *Qiniu) GenerateUploadToken(fileName string, dir string, nameBuilder fun
127127
}
128128
}
129129

130-
func (n *Qiniu) UploadFile(ctx context.Context, file io.Reader, size int64, key string) (*models.FileUploadResult, error) {
130+
func (n *Client) UploadFile(ctx context.Context, file io.Reader, size int64, key string) (*models.FileUploadResult, error) {
131131
put := &storage.PutPolicy{
132132
Scope: n.config.Bucket,
133133
}
@@ -145,7 +145,7 @@ func (n *Qiniu) UploadFile(ctx context.Context, file io.Reader, size int64, key
145145
}, nil
146146
}
147147

148-
func (n *Qiniu) UploadLocalFile(ctx context.Context, file string, key string) (*models.FileUploadResult, error) {
148+
func (n *Client) UploadLocalFile(ctx context.Context, file string, key string) (*models.FileUploadResult, error) {
149149
put := &storage.PutPolicy{
150150
Scope: n.config.Bucket,
151151
}

storage/s3/s3.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,26 @@ type Config struct {
2222
UseSSL bool `json:"use_ssl"`
2323
}
2424

25-
type S3 struct {
25+
type Client struct {
2626
config *Config
2727
client *minio.Client
2828
}
2929

30-
func NewS3(config *Config) (*S3, error) {
30+
func NewClient(config *Config) (*Client, error) {
3131
client, err := minio.New(config.EndPoint, &minio.Options{
3232
Creds: credentials.NewStaticV4(config.AccessKeyID, config.SecretAccessKey, config.Token),
3333
Secure: config.UseSSL,
3434
})
3535
if err != nil {
3636
return nil, err
3737
}
38-
return &S3{
38+
return &Client{
3939
config: config,
4040
client: client,
4141
}, nil
4242
}
4343

44-
func (s *S3) GenerateURL(key string) string {
44+
func (s *Client) GenerateURL(key string) string {
4545
if key == "" {
4646
return ""
4747
}
@@ -51,25 +51,25 @@ func (s *S3) GenerateURL(key string) string {
5151
return fmt.Sprintf("%s/%s/%s", s.config.EndPoint, s.config.Bucket, strings.TrimPrefix(key, "/"))
5252
}
5353

54-
func (s *S3) GenerateURLs(keys []string) []string {
54+
func (s *Client) GenerateURLs(keys []string) []string {
5555
urls := make([]string, len(keys))
5656
for i, key := range keys {
5757
urls[i] = s.GenerateURL(key)
5858
}
5959
return urls
6060
}
6161

62-
func (s *S3) GenerateImageURL(key string, width int) string {
63-
log.Warnf("S3 not support image resize")
62+
func (s *Client) GenerateImageURL(key string, width int) string {
63+
log.Warnf("Client not support image resize")
6464
return s.GenerateURL(key)
6565
}
6666

67-
func (s *S3) ExtractKeyFromURL(uri string) string {
67+
func (s *Client) ExtractKeyFromURL(uri string) string {
6868
key, _ := s.ExtractKeyFromURLWithMode(uri, true)
6969
return key
7070
}
7171

72-
func (s *S3) ExtractKeyFromURLWithMode(uri string, strict bool) (string, error) {
72+
func (s *Client) ExtractKeyFromURLWithMode(uri string, strict bool) (string, error) {
7373
if uri == "" {
7474
return "", nil
7575
}
@@ -97,7 +97,7 @@ func (s *S3) ExtractKeyFromURLWithMode(uri string, strict bool) (string, error)
9797
return parts[1], nil
9898
}
9999

100-
func (s *S3) UploadFile(ctx context.Context, file io.Reader, size int64, key string) (*models.FileUploadResult, error) {
100+
func (s *Client) UploadFile(ctx context.Context, file io.Reader, size int64, key string) (*models.FileUploadResult, error) {
101101
info, err := s.client.PutObject(ctx, s.config.Bucket, key, file, size, minio.PutObjectOptions{})
102102
if err != nil {
103103
return nil, err
@@ -107,7 +107,7 @@ func (s *S3) UploadFile(ctx context.Context, file io.Reader, size int64, key str
107107
}, nil
108108
}
109109

110-
func (s *S3) UploadLocalFile(ctx context.Context, file string, key string) (*models.FileUploadResult, error) {
110+
func (s *Client) UploadLocalFile(ctx context.Context, file string, key string) (*models.FileUploadResult, error) {
111111
info, err := s.client.FPutObject(ctx, s.config.Bucket, key, file, minio.PutObjectOptions{})
112112
if err != nil {
113113
return nil, err

0 commit comments

Comments
 (0)