gfs

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: Apache-2.0 Imports: 13 Imported by: 7

README

Go Report Card Go.Dev reference Sourcegraph Release

gfs

gfs is a file storage library for Golang. It provides one interface to interact with many types of fs. When you use gfs, you're not only protected from vendor lock-in, you'll also have a consistent experience for which ever storage is right for you.

Install

go get github.com/pkg6/gfs

Officially supported adapters

adapter Interface

You can always create an adapter yourself.

Documentation

Index

Constants

View Source
const (
	DiskNameLocal                   = "LOCAL"
	DiskNameOSS                     = "OSS"
	DiskNameCOS                     = "COS"
	DiskNameBOS                     = "BOS"
	DiskNameGoogleCloudCloudStorage = "CloudStorage"
	DiskNameQiNiuKoDo               = "KODO"

	HeaderGetLength      = "content-length"
	HeaderGetContentType = "content-type"

	PathTypeFile      = "file"
	PathTypeDirectory = "directory"
	ModePublicString  = "public"
	ModePrivateString = "private"
	ModeFilePublic    = 0644
	ModeFilePrivate   = 0600
	ModeDirPublic     = 0755
	ModeDirPrivate    = 0700
)

Variables

View Source
var (
	ConfigPtrTag                 = "gfs"
	ConfigPtrSplitTagDefaultDisk = "default"
)

Functions

func Base64Decode added in v0.1.2

func Base64Decode(s string) ([]byte, error)

func Base64Encode added in v0.1.2

func Base64Encode(src []byte) string

func Base64Reader added in v0.1.2

func Base64Reader(fi io.Reader) (string, error)

Base64Reader f, _ := os.Open("./_example/1.jpeg") f.Seek(0, 0) gfs.Base64Reader(f)

func BucketURLMake

func BucketURLMake(cdn, endpoint, bucket string) (*url.URL, error)

func Md5Reader added in v0.1.2

func Md5Reader(fr io.Reader) (string, error)

Md5Reader f, _ := os.Open("./_example/1.jpeg") f.Seek(0, 0) gfs.Md5Reader(f)

func Md5String added in v0.1.2

func Md5String(str string) string

func PublicURLMake

func PublicURLMake(domain, key string) (*url.URL, error)

func PublicURLRead

func PublicURLRead(publicURL string) ([]byte, error)

func Sha1String added in v0.1.2

func Sha1String(str string) string

func Sha256String added in v0.1.2

func Sha256String(str string) string

Types

type AbstractAdapter

type AbstractAdapter struct {
	// contains filtered or unexported fields
}

func (*AbstractAdapter) ApplyPathPrefix

func (a *AbstractAdapter) ApplyPathPrefix(path string) string

func (*AbstractAdapter) SetPathPrefix

func (a *AbstractAdapter) SetPathPrefix(prefix string)

type FsManage

type FsManage struct {
	// contains filtered or unexported fields
}

func New

func New() *FsManage

func NewConfig

func NewConfig(config any) (*FsManage, error)

func (*FsManage) Adapter

func (f *FsManage) Adapter(disk string) (IAdapter, error)

Adapter 根据驱动名称找到适配器

func (*FsManage) Copy

func (f *FsManage) Copy(source, destination string) (bool, error)

func (*FsManage) Delete

func (f *FsManage) Delete(path string) (int64, error)

func (*FsManage) DiskExist

func (f *FsManage) DiskExist(disk string) bool

DiskExist 判断驱动是否存在

func (*FsManage) Disks

func (f *FsManage) Disks() []string

Disks 获取注册所有的驱动

func (*FsManage) Exist

func (f *FsManage) Exist(path string) (bool, error)

func (*FsManage) Extend

func (f *FsManage) Extend(adapter IAdapter, names ...string) *FsManage

Extend 扩展

func (*FsManage) ExtendConfigPtr

func (f *FsManage) ExtendConfigPtr(config any) error

func (*FsManage) MimeType

func (f *FsManage) MimeType(path string) (string, error)

func (*FsManage) Move

func (f *FsManage) Move(source, destination string) (bool, error)

func (*FsManage) Read

func (f *FsManage) Read(path string) ([]byte, error)

func (*FsManage) Size

func (f *FsManage) Size(path string) (int64, error)

func (*FsManage) URL

func (f *FsManage) URL(path string) (*url.URL, error)

func (*FsManage) Update

func (f *FsManage) Update(path string, contents []byte) error

func (*FsManage) UpdateStream

func (f *FsManage) UpdateStream(path, resource string) error

func (*FsManage) Write

func (f *FsManage) Write(path string, contents []byte) error

func (*FsManage) WriteReader

func (f *FsManage) WriteReader(path string, reader io.Reader) error

func (*FsManage) WriteStream

func (f *FsManage) WriteStream(path, resource string) error

type IAdapter

type IAdapter interface {
	IFS
	// DiskName Default Disk Name
	DiskName() string
}

type IAdapterConfig

type IAdapterConfig interface {
	NewAdapter() IAdapter
	URL(path string) (*url.URL, error)
	UseBucket(bucket string) string
}

type IFS

type IFS interface {
	// Bucket Reselect Bucket
	Bucket(bucket string) IAdapter

	URL(path string) (*url.URL, error)
	// Exist Determine if the file exists
	Exist(path string) (bool, error)
	// WriteReader write file content and return full path
	WriteReader(path string, reader io.Reader) error
	// Write  file content and return full path
	Write(path string, contents []byte) error
	// WriteStream Resource file write returns full path
	WriteStream(path, resource string) error
	// Read Read file
	Read(path string) ([]byte, error)
	// Delete  Deleting files returns the number of deleted files
	Delete(path string) (int64, error)
	// Size Get File Size
	Size(path string) (int64, error)
	// Update  the file content and return the updated full path
	Update(path string, contents []byte) error
	// UpdateStream Return the updated full path based on resource file updates
	UpdateStream(path, resource string) error
	// MimeType Get File MimeType
	MimeType(path string) (string, error)
	// Move move file
	Move(source, destination string) (bool, error)
	// Copy copy file
	Copy(source, destination string) (bool, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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