hosts

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNameAlreadyRegistered = errors.New("name already registered")
	ErrInvalidName           = errors.New("name does not match this regular expression: " + namePattern)
)

Errors that may occur when registering a host provider.

Functions

func ReadSQLFileFromFS

func ReadSQLFileFromFS(fsys fs.FS) ([]string, error)

ReadSQLFileFromFS walk the directory and read *.sql files from FS such as embed.FS.

func Register

func Register(p *Properties) error

Register a new host.

func Start

func Start(d *Dependencies)

Start all hosts.

Types

type Dependencies

type Dependencies struct {
	Mysql  *gorm.DB
	Redis  *redis.Client
	Mailer mail.Mailer
	Queue  *queue.Client
}

Dependencies of hosts.

type Host

type Host interface {
	// CreateFromLinks create shared links based on the input original links.
	CreateFromLinks(ctx context.Context, userID string, originalLinks []string, createBy string) (sharedLinks map[string]*share.Share, err error)

	// GetStatuses return the statuses of each host shared link.
	GetStatuses(ctx context.Context, userID string, hostSharedLinks []string) (statuses map[string]share.State, err error)

	// GetStatistics return the statistics of each host shared link.
	GetStatistics(ctx context.Context, userID string, hostSharedLinks []string) (details map[string]share.Statistics, err error)

	// Delete delete shared links by original links.
	Delete(ctx context.Context, userID string, originalLinks []string) error

	// HostInfo returns basic information of the host.
	HostInfo(ctx context.Context, userID string, options map[string]any) (resp map[string]any, err error)
}

Host is an interface of file hosting provider.

type HostWithProperties

type HostWithProperties struct {
	Host
	// contains filtered or unexported fields
}

HostWithProperties save properties for hosts.

func Get

func Get(name string) *HostWithProperties

Get a host provider by name.

func GetAll

func GetAll() []*HostWithProperties

GetAll return all host providers.

func (*HostWithProperties) CreateTableStatements

func (h *HostWithProperties) CreateTableStatements() []string

CreateTableStatements returns the statements to create tables of the host.

func (*HostWithProperties) Name

func (h *HostWithProperties) Name() string

Name returns the host's name.

type Properties

type Properties struct {
	// Name is the host's name.
	// The name must match this regular expression: `^[0-9A-Za-z_]{1,32}$`
	Name string

	// New is the function to create a Host instance.
	New func(d *Dependencies) Host

	// CreateTableStatements return the statements to create tables in mysql database.
	// The name of tables must be prefixed with the host provider's name.
	// If the host do not need mysql database, this property can be empty.
	CreateTableStatements []string
}

Properties of a host.

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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