feat(storage): add cos support

This commit is contained in:
neo-f
2023-03-23 13:52:44 +08:00
parent 05c133a4b5
commit a56f0b8150
13 changed files with 283 additions and 90 deletions

View File

@@ -1,7 +1,6 @@
package config
import (
"net/url"
"os"
"path/filepath"
"runtime"
@@ -11,14 +10,9 @@ import (
"github.com/go-playground/validator"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cast"
"github.com/spf13/viper"
)
var ENVS = [][2]string{
{"本地测试环境", "http://localhost:8080"},
}
type Config struct {
IsLocal bool
Debug bool `mapstructure:"debug"`
@@ -36,33 +30,6 @@ type Config struct {
}
}
type ossConfig struct {
Schema string
Endpoint string
AccessID string
AccessSecret string
Region string
Bucket string
Secure bool
}
func (c *Config) GetOSSConfig() *ossConfig {
oss, err := url.Parse(c.Databases.OSS)
if err != nil {
log.Fatal().Err(err).Msg("parse oss config error")
}
accessSecret, _ := oss.User.Password()
return &ossConfig{
Schema: oss.Scheme,
Endpoint: oss.Host,
AccessID: oss.User.Username(),
AccessSecret: accessSecret,
Region: oss.Query().Get("region"),
Bucket: oss.Query().Get("bucket"),
Secure: cast.ToBool(oss.Query().Get("secure")),
}
}
var (
c *Config
once sync.Once

View File

@@ -23,3 +23,7 @@ const (
LogTagStaffID = "staff_id"
LogTagTraceID = "trace_id"
)
var ENVS = [][2]string{
{"本地测试环境", "http://localhost:8080"},
}