mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-22 10:33:13 +00:00
Each implementation keeps its provider client in an interface{} field that
Setup assigns, so an unconfigured store holds nil - and asserting nil to
the provider's client type panics:
panic: interface conversion: interface {} is nil, not *oss.Client
The upload endpoint reaches that path for any request naming a provider
the deployment never configured.
Three more things were wrong in the same files. OXS.Setup printed a
failure and returned the store anyway, handing back exactly the broken
object that panics. HuaWeiOBS.UpLoad printed the provider's error and
returned nil, so a failed upload reported success. Both it and
QiNiuKODO.UpLoad asserted the local path was a string without checking.
The tests asked the reader to paste their own credentials, so they failed
for everyone who did not. They now cover the guards and skip the part
that needs a provider unless credentials are in the environment.
38 lines
1005 B
Go
38 lines
1005 B
Go
package file_store
|
|
|
|
import "fmt"
|
|
|
|
type OXS struct {
|
|
// Endpoint 访问域名
|
|
Endpoint string
|
|
// AccessKeyID AK
|
|
AccessKeyID string
|
|
// AccessKeySecret AKS
|
|
AccessKeySecret string
|
|
// BucketName 桶名称
|
|
BucketName string
|
|
}
|
|
|
|
// Setup 配置文件存储driver
|
|
//
|
|
// A failed Setup used to be printed and the store returned anyway, so the
|
|
// caller received one whose Client was nil - which panicked on first use. The
|
|
// error is returned instead.
|
|
func (e *OXS) Setup(driver DriverType, options ...ClientOption) (FileStoreType, error) {
|
|
var fileStore FileStoreType
|
|
switch driver {
|
|
case AliYunOSS:
|
|
fileStore = new(ALiYunOSS)
|
|
case HuaweiOBS:
|
|
fileStore = new(HuaWeiOBS)
|
|
case QiNiuKodo:
|
|
fileStore = new(QiNiuKODO)
|
|
default:
|
|
return nil, fmt.Errorf("unsupported file store driver %q", driver)
|
|
}
|
|
if err := fileStore.Setup(e.Endpoint, e.AccessKeyID, e.AccessKeySecret, e.BucketName, options...); err != nil {
|
|
return nil, fmt.Errorf("file store %s: %w", driver, err)
|
|
}
|
|
return fileStore, nil
|
|
}
|