store

package
v0.0.0-...-8b94866 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: Unlicense Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AvailableModules

func AvailableModules() map[string]Module

func ContentTypeInList

func ContentTypeInList(contentType string, contentTypeList []string) bool

func ModuleConfigSkeletons

func ModuleConfigSkeletons() map[string]any

func ModuleNames

func ModuleNames() []string

func RegisterModule

func RegisterModule(
	serviceName string,
	module Module,
)

func UnmarshalModuleConfigFromYaml

func UnmarshalModuleConfigFromYaml(conf any) map[string]any

Types

type Config

type Config struct {
	NameGenerationKey string `env:"FILENAME_GENERATION_KEY" yaml:"filename_generation_key" json:"filename_generation_key"`
	StoreService      string `env:"STORE_SERVICE" yaml:"store_service" json:"store_service"`

	Modules map[string]any `env:",map,squash" yaml:",inline,omitempty"`

	ImagesBaseURL string `env:"IMAGES_BASE_URL" yaml:"images_base_url" json:"images_base_url"`
}

func ConfigSkeleton

func ConfigSkeleton() Config

func ParseConfigFromEnv

func ParseConfigFromEnv(prefix string) (cfg Config, err error)

ParseConfigFromEnv populate the configuration by looking up the environment variables.

type Module

type Module struct {
	// ServiceConfigSkeleton returns an instance of config used to initialize
	// the service. This skeleton contains a config structure.
	ServiceConfigSkeleton func() ServiceConfig

	// NewService create a storage service backend connection. This is
	// usually initialize the client of the object storage.
	NewService func(config ServiceConfig) (Service, error)
}

Module contains attributes which describe a storage module.

type Object

type Object interface {
	io.Reader
	io.Seeker
	io.WriterAt
}

type Service

type Service interface {
	PutObject(objectKey string, content io.Reader) (uploadInfo *UploadInfo, err error)
	GetObject(objectKey string) (stream *bytes.Buffer, err error)
	GetPublicObject(objectKey string) (string, error)
}

func NewServiceClient

func NewServiceClient(
	serviceName string,
	config any,
) (Service, error)

type ServiceConfig

type ServiceConfig any

type Store

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

func New

func New(config Config) (*Store, error)

func (*Store) Download

func (mediaStore *Store) Download(sourceKey string) (buffer *bytes.Buffer, err error)

func (*Store) GenerateName

func (mediaStore *Store) GenerateName(stream io.Reader) string

GenerateName is used to generate a name, for file or other identifier based on the content. It utilized hash so the result could be used to prevent duplicates when storing the media object

func (*Store) GetPublicURL

func (mediaStore *Store) GetPublicURL(sourceKey string) (publicURL string, err error)

func (*Store) Upload

func (mediaStore *Store) Upload(
	mediaName string,
	contentSource io.Reader,
	mediaType media.MediaType,
) (uploadInfo *UploadInfo, err error)

type UploadInfo

type UploadInfo struct {
	Bucket       string
	ETag         string
	Key          string
	LastModified time.Time
	Location     string
	Output       *bytes.Buffer
	Size         int
	UploadID     string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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