store

package
v0.0.0-...-ad531c1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 1 Imported by: 3

README

文件上传功能

这里也是面向接口编程,因为文件上传可能会有很多总方式:

  1. 上传本地
  2. 上传阿里云
  3. 上传腾讯云
  4. ...

所以面向接口编程是一个不错的选择

// Uploader 文件上传接口
type Uploader interface {
	// Upload 上传文件到云端
	Upload(*UploadParam) (*UploadResult, error)
}

当然,目前只有一个上传的接口,按理来说至少还需要一个删除废物文件的接口.

Documentation

Overview

@Author: Ciusyan 2023/2/8

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type UploadParam

type UploadParam struct {
	// 操作云上哪一个资源
	BucketName string `json:"bucket_name"`
	// 上传的文件路径
	FilePath string
	// 待上传的文件流
	FileStream multipart.File `json:"file_stream"`
}

UploadParam 文件上传参数

func NewUploadParam

func NewUploadParam(bucketName string, filePath string, file multipart.File) *UploadParam

NewUploadParam 从文件流中上传

func (*UploadParam) Validate

func (u *UploadParam) Validate() bool

Validate 简单校验参数

type UploadResult

type UploadResult struct {
	// 访问的绝对路径 url
	AbsoluteURL string `json:"absolute_url"`
	// 访问的相对路径 uri
	RelativeURI string `json:"relative_uri"`

	// 如果是视频,将封面相对路径返回
	CoverRelativeURI string `json:"cover_relative_uri"`
}

UploadResult 文件上传返回结果

func NewUploadResult

func NewUploadResult() *UploadResult

type Uploader

type Uploader interface {
	// Upload 上传文件到云端
	Upload(*UploadParam) (*UploadResult, error)
	// Delete 删除云端的视频,也需要知道是删除哪里的资源,叫什么名字,可删除多个
	Delete(bucketName string, filePaths ...string) error
}

Uploader 文件上传接口

Directories

Path Synopsis
@Author: Ciusyan 2023/2/8
@Author: Ciusyan 2023/2/8

Jump to

Keyboard shortcuts

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