Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #1

Merged
merged 2 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package config

import (
"github.com/cpyun/cpyun-admin-core/config/driver"
"fmt"
"github.com/cpyun/cpyun-admin-core/config/driver"
)

type Config struct {
Expand All @@ -26,17 +26,15 @@ type Config struct {
//Pgsql Pgsql `mapstructure:"pgsql" json:"pgsql" yaml:"pgsql"`
//DBList []DB `mapstructure:"db-list" json:"db-list" yaml:"db-list"`
//// oss
//Local Local `mapstructure:"local" json:"local" yaml:"local"`
//Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"`
//AliyunOSS AliyunOSS `mapstructure:"aliyun-oss" json:"aliyunOSS" yaml:"aliyun-oss"`
//HuaWeiObs HuaWeiObs `mapstructure:"hua-wei-obs" json:"huaWeiObs" yaml:"hua-wei-obs"`
//TencentCOS TencentCOS `mapstructure:"tencent-cos" json:"tencentCOS" yaml:"tencent-cos"`
Storage Storage `mapstructure:"storage" json:"mysql" yaml:"storage"`

//
//Excel Excel `mapstructure:"excel" json:"excel" yaml:"excel"`
//Timer Timer `mapstructure:"timer" json:"timer" yaml:"timer"`
//
//// 跨域配置
//Cors CORS `mapstructure:"cors" json:"cors" yaml:"cors"`
Extend interface{} `yaml:"extend"`
}

// 多db改造
Expand Down
24 changes: 24 additions & 0 deletions config/storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package config

type Storage struct {
FilesystemCloud string
Local interface{}
Minio Minio
Qiniu Qiniu
AliyunOSS AliyunOSS
}

type Minio struct {
Endpoint string
AccessKeyID string `mapstructure:"access-key-id" json:"access-key-id" yaml:"access-key-id"`
SecretAccessKey string `mapstructure:"secret-access-key" json:"secret-access-key" yaml:"secret-access-key"`
Secure bool `mapstructure:"secure" json:"secure" yaml:"secure"`
Region string `mapstructure:"region" json:"region" yaml:"region"`
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"`
}

type Qiniu struct {
}

type AliyunOSS struct {
}
35 changes: 22 additions & 13 deletions sdk/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package filesystem

import (
"context"
"github.com/cpyun/cpyun-admin-core/config"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"log"
Expand All @@ -16,31 +17,39 @@ type FileSystem struct {
}

//
func New() FileSystem {
func New() *FileSystem {
ctx := context.Background()
option := config.Settings.Storage.Minio

endpoint := "192.168.99.93:9090"
accessKeyID := "LaBY0JlcsRH4pac7uM17wxCB"
secretAccessKey := "neTSW#OrzWR7a^VrXvlp6QZ8bo!akWDMTy3b"
useSSL := false
bucketName := "notice"

s3Client, err := minio.New(endpoint, &minio.Options{
Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
Secure: useSSL,
s3Client, err := minio.New(option.Endpoint, &minio.Options{
Creds: credentials.NewStaticV4(option.AccessKeyID, option.SecretAccessKey, ""),
Secure: option.Secure,
})

if err != nil {
log.Fatalln(err)
//log.Fatalln(err)
log.Println(err)
}

return FileSystem{
return &FileSystem{
client: s3Client,
ctx: ctx,
bucketName: bucketName,
bucketName: option.Bucket,
}
}

// 设置上下文
func (f *FileSystem) SetContext(ctx context.Context) *FileSystem {
f.ctx = ctx
return f
}

// 设置bucket
func (f *FileSystem) SetBucket(bucketName string) *FileSystem {
f.bucketName = bucketName
return f
}

// 保存文件
func (f FileSystem) PutFile(path string, file *multipart.FileHeader, rule string) (minio.UploadInfo, error) {
name := generateHashName(rule) + filepath.Ext(file.Filename)
Expand Down