go_object_storage

package module
v0.0.0-...-19e9449 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 5 Imported by: 0

README

go-object-storage

Godoc Build Status GitHub release MIT License Commit activity Average time to resolve an issue Percentage of issues still open

go-object-storage 是一个用go开发的针对主流云服务商对象存储SDK集成包。其实现了文件路径自动生产,不同存储引擎简单配置即可使用,欢迎使用。

安装

$ go get -u github.com/fuguowei93/go-object-storage

使用指南

package main

import (
	"fmt"
	objectstorage "github.com/fuguowei93/go-object-storage"
	objectstoragedrives "github.com/fuguowei93/go-object-storage/drives"
	"github.com/fuguowei93/go-package-demo/config"
)

// 配置存储引擎
func GetObjectStorage(isAutomaticProductionPath bool) *objectstorage.ObjectStorage {
	return &objectstorage.ObjectStorage{
		Drive: objectstoragedrives.Kodo{
			AccessKey: config.KodoConfig.AccessKey,
			SecretKey: config.KodoConfig.SecretKey,
			Bucket:    config.KodoConfig.Bucket,
		},
		IsAutomaticProductionPath: isAutomaticProductionPath,
		FilePathPrefix:            "test/",
		IsAppendExt:               false,
		BaseUrl:                   "http://qynr9haq9.hd-bkt.clouddn.com/",
	}
}

func main() {
    // 转存网络文件
	url := "https://tenfei03.cfp.cn/creative/vcg/veer/800/new/VCG41N813911068.jpg"
	fileInfo, _ := GetObjectStorage(true).PutNetFile(url)
	fmt.Println(fileInfo)
}

上传指定内容,指定存储路径

localFile := "111111111111111"
key := "temp/11111111111.txt"
fileInfo, err := GetObjectStorage(false).SetFilePath(key).PutStr(localFile)
if err != nil {
    t.Errorf(err.Error())
}
fmt.Println(fileInfo)

上传本地文件

localFile := "./golang.jpg"
fileInfo, err := GetObjectStorage(true).PutFile(localFile)
if err != nil {
    t.Errorf(err.Error())
}
fmt.Println(fileInfo)

参数说明

ObjectStorage
参数 说明
Drive 对象存储驱动
IsAutomaticProductionPath 是否自动生产文件路径
FilePathPrefix 指定文件存储前缀
IsAppendExt 是否自动拼接文件名后缀
BaseUrl 基础url路径

实现的存储引擎

  • 七牛云 kodo
  • 阿里云 oos
  • 腾讯云 cos
  • Amazon S3

Enjoy it! ❤

参照

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ObjectStorage

type ObjectStorage struct {
	// 存储驱动
	Drive drives.ObjectStorageDrive
	// 是否依据文件类型自动补充文件后缀
	IsAppendExt bool
	// 路径前缀
	FilePathPrefix string
	// 是否自动生产路径
	IsAutomaticProductionPath bool
	// 文件存储路径
	FilePathKey string
	// 文件存储基础URL地址
	BaseUrl string
}

func (*ObjectStorage) BuildBasePath

func (receiver *ObjectStorage) BuildBasePath() string

BuildBasePath 生成基础路径

func (*ObjectStorage) PutFile

func (receiver *ObjectStorage) PutFile(localFile string) (UploadFileInfo, error)

PutFile 上传本地文件

func (*ObjectStorage) PutFileByFileInfo

func (receiver *ObjectStorage) PutFileByFileInfo(fileInfo drives.FileInfo) (UploadFileInfo, error)

执行不同类型的文件上传 +------------------------------------------------------------------------------------------ PutFileByFileInfo 通过自行构建FileInfo上传

func (*ObjectStorage) PutFileHeaderFile

func (receiver *ObjectStorage) PutFileHeaderFile(file *multipart.FileHeader) (UploadFileInfo, error)

PutFileHeaderFile 读取文件流中文件信息

func (*ObjectStorage) PutNetFile

func (receiver *ObjectStorage) PutNetFile(fileUrl string) (UploadFileInfo, error)

PutNetFile 上传网络文件

func (*ObjectStorage) PutStr

func (receiver *ObjectStorage) PutStr(content string) (UploadFileInfo, error)

PutStr 上传文本内容

func (*ObjectStorage) SetFilePath

func (receiver *ObjectStorage) SetFilePath(filePathKey string) *ObjectStorage

SetFilePath 设置文件存储路径

type UploadFileInfo

type UploadFileInfo struct {
	// 存储文件的完整url
	Url string
	// 存储文件的路径
	Key string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL