You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.1 KiB
Go

package initialize
import (
"fmt"
"gopkg.in/yaml.v3"
"os"
"uploader/config"
"uploader/global"
"uploader/utils/storage"
)
const FilePath = "config.yaml"
func InitConfig() *config.Config {
currentDir, err := os.Getwd()
if err != nil {
panic(err)
}
fmt.Println("currentDir: " + currentDir)
filePath := currentDir + "/" + FilePath
//filePath := "/var/www/gold-shop/" + FilePath
fmt.Println("filepath: " + filePath)
content, err := os.ReadFile(filePath)
if err != nil {
fmt.Printf("err: %v\n", err)
panic(err)
}
var conf config.Config
if err := yaml.Unmarshal(content, &conf); err != nil {
fmt.Printf("err: %v\n", err)
panic(err)
}
return &conf
}
func InitStorage() storage.Storage {
if global.Config.Storage.StorageType == "oss" {
return storage.NewOssStorage(global.Config.Storage.Oss)
} else if global.Config.Storage.StorageType == "obs" {
return storage.NewObsStorage(global.Config.Storage.Obs)
} else if global.Config.Storage.StorageType == "cos" {
return storage.NewCosStorage(global.Config.Storage.Cos)
} else {
panic("存储系统不存在")
}
}