oss

package
v3.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// URLTemplate default URL template
	URLTemplate = "/system/{{class}}/{{primary_key}}/{{column}}/{{filename_with_hash}}"
	// Storage the storage used to save medias
	Storage oss.StorageInterface = filesystem.New("public")
)
View Source
var DefaultRetrieveHandler = func(oss OSS, path string) (base.FileInterface, error) {
	result, err := Storage.GetStream(path)
	if f, ok := result.(base.FileInterface); ok {
		return f, err
	}

	if err == nil {
		buf := []byte{}
		if buf, err = io.ReadAll(result); err == nil {
			result := ClosingReadSeeker{bytes.NewReader(buf)}
			result.Seek(0, 0)
			return result, err
		}
	}
	return nil, err
}

DefaultRetrieveHandler used to retrieve file

View Source
var DefaultStoreHandler = func(oss OSS, path string, option *base.Option, reader io.Reader) error {
	_, err := Storage.Put(path, reader)
	return err
}

DefaultStoreHandler used to store reader with default Storage

View Source
var DefaultURLTemplateHandler = func(oss OSS, option *base.Option) (url string) {
	if url = option.Get("URL"); url == "" {
		url = URLTemplate
	}

	url = strings.Join([]string{strings.TrimSuffix(Storage.GetEndpoint(), "/"), strings.TrimPrefix(url, "/")}, "/")
	if strings.HasPrefix(url, "/") {
		return url
	}

	for _, prefix := range []string{"https://", "http://"} {
		url = strings.TrimPrefix(url, prefix)
	}

	return "//" + url
}

DefaultURLTemplateHandler used to generate URL and save into database

Functions

This section is empty.

Types

type ClosingReadSeeker

type ClosingReadSeeker struct {
	io.ReadSeeker
}

ClosingReadSeeker implement Closer interface for ReadSeeker

func (ClosingReadSeeker) Close

func (ClosingReadSeeker) Close() error

Close implement Closer interface for Buffer

type OSS

type OSS struct {
	base.Base
}

OSS common storage interface

func (OSS) GetURLTemplate

func (o OSS) GetURLTemplate(option *base.Option) (url string)

GetURLTemplate URL's template

func (OSS) Retrieve

func (o OSS) Retrieve(path string) (base.FileInterface, error)

Retrieve retrieve file content with url

func (OSS) Store

func (o OSS) Store(path string, option *base.Option, reader io.Reader) error

Store save reader's content with path

func (OSS) String

func (o OSS) String() string

func (OSS) URL

func (o OSS) URL(styles ...string) string

URL return file's url with given style

Jump to

Keyboard shortcuts

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