media

package
v1.72.33 Latest Latest
Warning

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

Go to latest
Published: May 1, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BeginFunc

type BeginFunc func(ctx context.Context, category, filename string, size int64)

Callbacks

type Client

type Client interface {
	// Put returns link {Domain}/{Bucket}/{Category}/{RandPrefix}/{Filename}
	Put(ctx context.Context, category, filename string, size int64, body io.Reader) (link string, err error)
	// PutFile is alias Put with opening local file
	PutFile(ctx context.Context, category, filepath string) (link string, err error)
	// PutData is alias Put
	PutData(ctx context.Context, category, filename string, data []byte) (link string, err error)
	// PutImage ...
	PutImage(
		ctx context.Context, category, filename string, img image.Image, typ ImageType) (link string, err error)
	// PutMultipartThumbnail ...
	PutMultipartThumbnail(
		ctx context.Context, category string,
		file *multipart.FileHeader, typ ImageType, maxPixelSize uint) (link string, err error)
}

Client of S3 storage

For opening use func Open

type Config

type Config struct {
	RandPrefixLen int `desc:"rand file prefix for safe"`

	Local    bool   `desc:"enable local storage for files"`
	LocalDir string `desc:"local storage directory"`
	LocalURL string `desc:"target url file prefix"`

	S3AccessKey string `encoding:"manual" desc:"access key or login or user, for example: 32423_goservice"`
	S3SecretKey string `encoding:"manual" desc:"secret key or password"`
	S3AuthToken string `encoding:"manual" desc:"optional"`
	S3EndPoint  string `desc:"provider api url, for example: s3.selcdn.ru"`
	S3Domain    string `desc:"storage domain, for example: https://56756.selcdn.ru"`
	S3Region    string `desc:"for example: ru-1a"`
	S3Bucket    string `desc:"service bucket root, for example: goservice"`
	S3Insecure  bool
}

Config for local storage or s3 connection

func (*Config) ValidAndRepair

func (c *Config) ValidAndRepair() error

ValidAndRepair config

type FinishFunc

type FinishFunc func(ctx context.Context, category, filename, link string, size int64, err error, dur time.Duration)

Callbacks

type ImageType

type ImageType int
const (
	ImageJPG ImageType = iota
	ImagePNG
)

type Logger

type Logger interface {
	Logger() logger.Logger
}

type Storage

type Storage interface {
	Client
	// SetBeginCallback func
	SetBeginCallback(BeginFunc)
	// SetFinishCallback func
	SetFinishCallback(FinishFunc)
}

Storage client with config

func Open

func Open(conf Config, log logger.Logger) (Storage, error)

Open local or s3 storage

required fields:

for remote storage: AccessKey, SecretKey, Region, EndPoint, Domain, Bucket

for local storage: Local, LocalDir, LocalURL, Bucket (optional)

Jump to

Keyboard shortcuts

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