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("存储系统不存在") } }