代码拉取完成,页面将自动刷新
// Package embedfs
// @Link https://gitee.com/linngc/central-mirror
// @Copyright Copyright (c) 2024 central-mirror CLI
// @Author linngc
// @License
package embedfs
import (
"errors"
"fmt"
"gitee.com/linngc/central-mirror/contrib/container/core/memorycache/implement/model"
toolkitIo "gitee.com/linngc/central-mirror/contrib/container/utility/io"
"io"
"os"
"path"
)
// GetAbsoluteLocation 获取绝对路径
func (c *EmbedFs) getAbsoluteLocation(moduleName string) string {
return path.Join(c.cfgConfig.Storage, c.GetLocation(moduleName))
}
// GetLocation 组装并获取存储位置
// @param moduleName 参数是 文件模块名称(请求的文件全路径名称)
// @return 缓存位置(Storage) + 缓存类型(cosType) + 代理类型(proxy) + 代理文件相对路径(moduleName)
// storage/embedfs/alpine/v3.18/main/x86_64/acf-awall-0.4.1-r4.apk
// @Storage ./storage
// @cosType embedfs
// @proxy alpine
// @moduleName v3.18/main/x86_64/acf-awall-0.4.1-r4.apk
func (c *EmbedFs) GetLocation(moduleName string) string {
return path.Join(c.cosType.String(), c.proxy, moduleName)
}
// GetPath 获取存储文件夹
func (c *EmbedFs) getPath() string {
return path.Join(c.cfgConfig.Storage, c.cosType.String(), c.proxy)
}
// GetObjectsInfo 组装数据存储对象
func (c *EmbedFs) GetObjectsInfo(moduleName string, data []byte) (m *model.ObjectsInfo) {
m = &model.ObjectsInfo{Bucket: c.cosType.String(), Cache: c.cosType, Name: moduleName,
Location: c.GetLocation(moduleName), Size: int64(len(data)), Bytes: data}
return
}
// readerObject 获取对象
// @param moduleNames 参数是 文件模块名称(请求的文件全路径名称)
func (c *EmbedFs) readerObject(moduleName string) (byt []byte, err error) {
//读取文件时,要指定FileSystem下的相对路径
location := c.GetLocation(moduleName)
f, err := FileSystem.Open(location)
defer toolkitIo.CloseFile(f)
if err != nil || f == nil {
return byt, err
}
return io.ReadAll(f)
}
// fromObject 上传对象
// @param minioClient minio链接对象
// @param location 参数是 文件存储相对位置(请求的文件全路径名称)
// @param reader 文件byte信息
func (c *EmbedFs) fromObject(moduleName string, reader []byte) (err error) {
//创建文件夹时,要指定绝对路径(包含指定的缓存路径)
location := c.getAbsoluteLocation(moduleName)
dirPath := path.Dir(location)
if stat, err := os.Stat(dirPath); err != nil && os.IsNotExist(err) {
if err = os.MkdirAll(dirPath, os.ModePerm); err != nil {
return err
}
} else if !stat.IsDir() {
return errors.New(fmt.Sprintf("%s is not a dir\n", dirPath))
}
if err := os.WriteFile(location, reader, os.ModePerm); err != nil {
return err
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。