添加 MinIO 文件前缀配置并优化文件地址拼接逻辑

This commit is contained in:
2026-01-26 11:40:57 +08:00
committed by 张斌
parent c31848ae42
commit 647e88b21a

View File

@@ -19,6 +19,7 @@ import (
// IoConfig 映射 YAML 中的 minio 配置节点
type IoConfig struct {
FilePrefix string `yaml:"filePrefix"` // 文件前缀
Endpoint string `yaml:"endpoint"` // MinIO API 地址
AccessKey string `yaml:"accessKey"` // AK
SecretKey string `yaml:"secretKey"` // SK
@@ -36,6 +37,7 @@ func init() {
if !g.Cfg().MustGet(ctx, "minio").IsEmpty() {
// 加载 MinIO 配置(可从配置文件/环境变量读取,这里硬编码示例)
minioCfg = IoConfig{
FilePrefix: g.Cfg().MustGet(ctx, "filePrefix.endpoint").String(),
Endpoint: g.Cfg().MustGet(ctx, "minio.endpoint").String(),
AccessKey: g.Cfg().MustGet(ctx, "minio.accessKey").String(),
SecretKey: g.Cfg().MustGet(ctx, "minio.secretKey").String(),
@@ -123,14 +125,14 @@ func uploadFile(ctx context.Context, bucketName string, fileHeader *ghttp.Upload
return objectName, err
}
// GetIFileAddressPrefix 拼接图片前缀地址
func GetIFileAddressPrefix(ctx context.Context) (imageUrl string) {
// GetFileAddressPrefix 拼接图片前缀地址
func GetFileAddressPrefix(ctx context.Context) (imageUrl string) {
// 拼接图片前缀地址
var url = "http://"
if minioCfg.Secure {
url = "https://"
}
imgAddressPrefix := url + minioCfg.Endpoint + "/" + getBucketName(ctx)
imgAddressPrefix := url + minioCfg.FilePrefix + "/" + getBucketName(ctx)
return imgAddressPrefix
}