server

package
v0.0.0-...-7dfb9ec Latest Latest
Warning

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

Go to latest
Published: May 2, 2022 License: MIT Imports: 63 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SYMBOLS characters used for short-urls
	SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
)

Variables

This section is empty.

Functions

func CloseCheck

func CloseCheck(f func() error)

func LoveHandler

func LoveHandler(h http.Handler) http.HandlerFunc

LoveHandler Create a log handler for every request it receives.

func WrapIPFilter

func WrapIPFilter(next http.Handler, opts IPFilterOptions) http.Handler

WrapIPFilter is equivalent to newIPFilter(opts) then Wrap(next)

Types

type GDrive

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

GDrive is a storage backed by GDrive

func NewGDriveStorage

func NewGDriveStorage(clientJSONFilepath string, localConfigPath string, basedir string, chunkSize int, logger *log.Logger) (*GDrive, error)

NewGDriveStorage is the factory for GDrive

func (*GDrive) Delete

func (s *GDrive) Delete(ctx context.Context, token string, filename string) (err error)

Delete removes a file from storage

func (*GDrive) Get

func (s *GDrive) Get(ctx context.Context, token string, filename string) (reader io.ReadCloser, contentLength uint64, err error)

Get retrieves a file from storage

func (*GDrive) Head

func (s *GDrive) Head(ctx context.Context, token string, filename string) (contentLength uint64, err error)

Head retrieves content length of a file from storage

func (*GDrive) IsNotExist

func (s *GDrive) IsNotExist(err error) bool

IsNotExist indicates if a file doesn't exist on storage

func (*GDrive) Purge

func (s *GDrive) Purge(ctx context.Context, days time.Duration) (err error)

Purge cleans up the storage

func (*GDrive) Put

func (s *GDrive) Put(ctx context.Context, token string, filename string, reader io.Reader, contentType string, contentLength uint64) error

Put saves a file on storage

func (*GDrive) Type

func (s *GDrive) Type() string

Type returns the storage type

type IPFilterOptions

type IPFilterOptions struct {
	//explicity allowed IPs
	AllowedIPs []string
	//explicity blocked IPs
	BlockedIPs []string
	//block by default (defaults to allow)
	BlockByDefault bool
	// TrustProxy enable check request IP from proxy
	TrustProxy bool

	Logger interface {
		Printf(format string, v ...interface{})
	}
}

IPFilterOptions for ipFilter. Allowed takes precedence over Blocked. IPs can be IPv4 or IPv6 and can optionally contain subnet masks (/24). Note however, determining if a given IP is included in a subnet requires a linear scan so is less performant than looking up single IPs.

This could be improved with some algorithmic magic.

type LocalStorage

type LocalStorage struct {
	Storage
	// contains filtered or unexported fields
}

LocalStorage is a local storage

func NewLocalStorage

func NewLocalStorage(basedir string, logger *log.Logger) (*LocalStorage, error)

NewLocalStorage is the factory for LocalStorage

func (*LocalStorage) Delete

func (s *LocalStorage) Delete(ctx context.Context, token string, filename string) (err error)

Delete removes a file from storage

func (*LocalStorage) Get

func (s *LocalStorage) Get(ctx context.Context, token string, filename string) (reader io.ReadCloser, contentLength uint64, err error)

Get retrieves a file from storage

func (*LocalStorage) Head

func (s *LocalStorage) Head(ctx context.Context, token string, filename string) (contentLength uint64, err error)

Head retrieves content length of a file from storage

func (*LocalStorage) IsNotExist

func (s *LocalStorage) IsNotExist(err error) bool

IsNotExist indicates if a file doesn't exist on storage

func (*LocalStorage) Purge

func (s *LocalStorage) Purge(ctx context.Context, days time.Duration) (err error)

Purge cleans up the storage

func (*LocalStorage) Put

func (s *LocalStorage) Put(ctx context.Context, token string, filename string, reader io.Reader, contentType string, contentLength uint64) error

Put saves a file on storage

func (*LocalStorage) Type

func (s *LocalStorage) Type() string

Type returns the storage type

type OptionFn

type OptionFn func(*Server)

OptionFn is the option function type

func ClamavHost

func ClamavHost(s string) OptionFn

ClamavHost sets clamav host

func CorsDomains

func CorsDomains(s string) OptionFn

CorsDomains sets CORS domains

func EmailContact

func EmailContact(emailContact string) OptionFn

EmailContact sets email contact

func EnableProfiler

func EnableProfiler() OptionFn

EnableProfiler sets enable profiler

func FilterOptions

func FilterOptions(options IPFilterOptions) OptionFn

FilterOptions sets ip filtering

func ForceHTTPS

func ForceHTTPS() OptionFn

ForceHTTPS sets forcing https

func GoogleAnalytics

func GoogleAnalytics(gaKey string) OptionFn

GoogleAnalytics sets GA key

func HTTPAuthCredentials

func HTTPAuthCredentials(user string, pass string) OptionFn

HTTPAuthCredentials sets basic http auth credentials

func Listener

func Listener(s string) OptionFn

Listener set listener

func LogFile

func LogFile(logger *log.Logger, s string) OptionFn

LogFile sets log file

func Logger

func Logger(logger *log.Logger) OptionFn

Logger sets logger

func MaxUploadSize

func MaxUploadSize(kbytes int64) OptionFn

MaxUploadSize sets max upload size

func PerformClamavPrescan

func PerformClamavPrescan(b bool) OptionFn

PerformClamavPrescan enables clamav prescan on upload

func ProfileListener

func ProfileListener(s string) OptionFn

ProfileListener sets profile listener

func ProxyPath

func ProxyPath(s string) OptionFn

ProxyPath sets proxy path

func ProxyPort

func ProxyPort(s string) OptionFn

ProxyPort sets proxy port

func Purge

func Purge(days, interval int) OptionFn

Purge sets purge days and option

func RandomTokenLength

func RandomTokenLength(length int) OptionFn

RandomTokenLength sets random token length

func RateLimit

func RateLimit(requests int) OptionFn

RateLimit set rate limit

func TLSConfig

func TLSConfig(cert, pk string) OptionFn

TLSConfig sets TLS config

func TLSListener

func TLSListener(s string, t bool) OptionFn

TLSListener sets TLS listener and option

func TempPath

func TempPath(s string) OptionFn

TempPath sets temp path

func UseLetsEncrypt

func UseLetsEncrypt(hosts []string) OptionFn

UseLetsEncrypt set letsencrypt usage

func UseStorage

func UseStorage(s Storage) OptionFn

UseStorage set storage to use

func UserVoice

func UserVoice(userVoiceKey string) OptionFn

UserVoice sets UV key

func VirustotalKey

func VirustotalKey(s string) OptionFn

VirustotalKey sets virus total key

func WebPath

func WebPath(s string) OptionFn

WebPath sets web path

type S3Storage

type S3Storage struct {
	Storage
	// contains filtered or unexported fields
}

S3Storage is a storage backed by AWS S3

func NewS3Storage

func NewS3Storage(accessKey, secretKey, bucketName string, purgeDays int, region, endpoint string, disableMultipart bool, forcePathStyle bool, logger *log.Logger) (*S3Storage, error)

NewS3Storage is the factory for S3Storage

func (*S3Storage) Delete

func (s *S3Storage) Delete(ctx context.Context, token string, filename string) (err error)

Delete removes a file from storage

func (*S3Storage) Get

func (s *S3Storage) Get(ctx context.Context, token string, filename string) (reader io.ReadCloser, contentLength uint64, err error)

Get retrieves a file from storage

func (*S3Storage) Head

func (s *S3Storage) Head(ctx context.Context, token string, filename string) (contentLength uint64, err error)

Head retrieves content length of a file from storage

func (*S3Storage) IsNotExist

func (s *S3Storage) IsNotExist(err error) bool

IsNotExist indicates if a file doesn't exist on storage

func (*S3Storage) Purge

func (s *S3Storage) Purge(ctx context.Context, days time.Duration) (err error)

Purge cleans up the storage

func (*S3Storage) Put

func (s *S3Storage) Put(ctx context.Context, token string, filename string, reader io.Reader, contentType string, contentLength uint64) (err error)

Put saves a file on storage

func (*S3Storage) Type

func (s *S3Storage) Type() string

Type returns the storage type

type Server

type Server struct {
	AuthUser string
	AuthPass string

	VirusTotalKey    string
	ClamAVDaemonHost string

	TLSListenerOnly bool

	CorsDomains           string
	ListenerString        string
	TLSListenerString     string
	ProfileListenerString string

	Certificate string

	LetsEncryptCache string
	// contains filtered or unexported fields
}

Server is the main application

func New

func New(options ...OptionFn) (*Server, error)

New is the factory fot Server

func (*Server) RedirectHandler

func (s *Server) RedirectHandler(h http.Handler) http.HandlerFunc

RedirectHandler handles redirect

func (*Server) Run

func (s *Server) Run()

Run starts Server

type Storage

type Storage interface {
	// Get retrieves a file from storage
	Get(ctx context.Context, token string, filename string) (reader io.ReadCloser, contentLength uint64, err error)
	// Head retrieves content length of a file from storage
	Head(ctx context.Context, token string, filename string) (contentLength uint64, err error)
	// Put saves a file on storage
	Put(ctx context.Context, token string, filename string, reader io.Reader, contentType string, contentLength uint64) error
	// Delete removes a file from storage
	Delete(ctx context.Context, token string, filename string) error
	// IsNotExist indicates if a file doesn't exist on storage
	IsNotExist(err error) bool
	// Purge cleans up the storage
	Purge(ctx context.Context, days time.Duration) error

	// Type returns the storage type
	Type() string
}

Storage is the interface for storage operation

type StorjStorage

type StorjStorage struct {
	Storage
	// contains filtered or unexported fields
}

StorjStorage is a storage backed by Storj

func NewStorjStorage

func NewStorjStorage(access, bucket string, purgeDays int, logger *log.Logger) (*StorjStorage, error)

NewStorjStorage is the factory for StorjStorage

func (*StorjStorage) Delete

func (s *StorjStorage) Delete(ctx context.Context, token string, filename string) (err error)

Delete removes a file from storage

func (*StorjStorage) Get

func (s *StorjStorage) Get(ctx context.Context, token string, filename string) (reader io.ReadCloser, contentLength uint64, err error)

Get retrieves a file from storage

func (*StorjStorage) Head

func (s *StorjStorage) Head(ctx context.Context, token string, filename string) (contentLength uint64, err error)

Head retrieves content length of a file from storage

func (*StorjStorage) IsNotExist

func (s *StorjStorage) IsNotExist(err error) bool

IsNotExist indicates if a file doesn't exist on storage

func (*StorjStorage) Purge

func (s *StorjStorage) Purge(ctx context.Context, days time.Duration) (err error)

Purge cleans up the storage

func (*StorjStorage) Put

func (s *StorjStorage) Put(ctx context.Context, token string, filename string, reader io.Reader, contentType string, contentLength uint64) (err error)

Put saves a file on storage

func (*StorjStorage) Type

func (s *StorjStorage) Type() string

Type returns the storage type

Jump to

Keyboard shortcuts

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