sdobjectstore

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package sdobjectstore 对象存储服务,用于存储文件(例如阿里云OSS)

Index

Constants

View Source
const (
	DiscardTarget = TargetType(1)
	FileTarget    = TargetType(2)
	HttpTarget    = TargetType(3)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AliyunOssOptions

type AliyunOssOptions struct {
	Endpoint       string `json:"endpoint" toml:"endpoint"`
	AccessKey      string `json:"access_key" toml:"access_key"`
	AccessSecret   string `json:"access_secret" toml:"access_secret"`
	Bucket         string `json:"bucket" toml:"bucket"`
	Prefix         string `json:"prefix" toml:"prefix"`
	InternalPrefix string `json:"internal_prefix" toml:"internal_prefix"`
}

type Interface

type Interface interface {
	Store(src Source, objectName string) (*Target, error)
}
var (
	Discard Interface = discard{}
)

func NewAliyunOSS

func NewAliyunOSS(opts *AliyunOssOptions) (Interface, error)

type Options

type Options struct {
	Type           string `json:"type" toml:"type"`
	Root           string `json:"root" toml:"root"`
	Endpoint       string `json:"endpoint" toml:"endpoint"`
	AccessKey      string `json:"access_key" toml:"access_key"`
	AccessSecret   string `json:"access_secret" toml:"access_secret"`
	Bucket         string `json:"bucket" toml:"bucket"`
	Prefix         string `json:"prefix" toml:"prefix"`
	InternalPrefix string `json:"internal_prefix" toml:"internal_prefix"`
}

type Source

type Source interface {
	Open() (io.Reader, error)
	AsBytes() ([]byte, error)
	Filename() string
	ContentType() string
	Ext() string
	Size() int64
	Md5() string
	Sha256() string
}

func Bytes

func Bytes(data []byte, contentType string) Source

func File

func File(filename string, contentType string) Source

type Store

type Store struct {
	Interface
}

func Dir

func Dir(root string) Store

func New

func New(opts *Options) (Store, error)

func (Store) IsNil

func (s Store) IsNil() bool

func (Store) StoreData

func (s Store) StoreData(data []byte, objectName string) (*Target, error)

func (Store) StoreFile

func (s Store) StoreFile(filename, objectName string) (*Target, error)

func (Store) StoreFileFS

func (s Store) StoreFileFS(fsys fs.FS, fn string, objectName string) (*Target, error)

type Target

type Target struct {
	Typ            TargetType
	Prefix         string
	InternalPrefix string
	Path           string
}

func (*Target) HttpsUrl

func (t *Target) HttpsUrl() string

func (*Target) InternalUrl

func (t *Target) InternalUrl() string

func (*Target) Url

func (t *Target) Url() string

type TargetType

type TargetType int

Jump to

Keyboard shortcuts

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