server

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2021 License: MIT Imports: 62 Imported by: 6

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func LoveHandler

func LoveHandler(h http.Handler) http.HandlerFunc

LoveHandler Create a log handler for every request it receives.

func WrapIPFilter added in v1.1.0

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(token string, filename string) (err error)

Delete removes a file from storage

func (*GDrive) Get

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

Get retrieves a file from storage

func (*GDrive) Head

func (s *GDrive) Head(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 added in v1.2.0

func (s *GDrive) Purge(days time.Duration) (err error)

Purge cleans up the storage

func (*GDrive) Put

func (s *GDrive) Put(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 added in v1.1.0

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(token string, filename string) (err error)

Delete removes a file from storage

func (*LocalStorage) Get

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

Get retrieves a file from storage

func (*LocalStorage) Head

func (s *LocalStorage) Head(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 added in v1.2.0

func (s *LocalStorage) Purge(days time.Duration) (err error)

Purge cleans up the storage

func (*LocalStorage) Put

func (s *LocalStorage) Put(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 added in v1.1.7

func CorsDomains(s string) OptionFn

CorsDomains sets CORS domains

func EmailContact added in v1.3.1

func EmailContact(emailContact string) OptionFn

EmailContact sets email contact

func EnableProfiler

func EnableProfiler() OptionFn

EnableProfiler sets enable profiler

func FilterOptions added in v1.1.0

func FilterOptions(options IPFilterOptions) OptionFn

FilterOptions sets ip filtering

func ForceHTTPS added in v1.3.1

func ForceHTTPS() OptionFn

ForceHTTPS sets forcing https

func GoogleAnalytics

func GoogleAnalytics(gaKey string) OptionFn

GoogleAnalytics sets GA key

func HTTPAuthCredentials added in v1.3.1

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 added in v1.2.0

func MaxUploadSize(kbytes int64) OptionFn

MaxUploadSize sets max upload size

func ProfileListener

func ProfileListener(s string) OptionFn

ProfileListener sets profile listener

func ProxyPath added in v1.1.0

func ProxyPath(s string) OptionFn

ProxyPath sets proxy path

func ProxyPort added in v1.2.0

func ProxyPort(s string) OptionFn

ProxyPort sets proxy port

func Purge added in v1.2.0

func Purge(days, interval int) OptionFn

Purge sets purge days and option

func RandomTokenLength added in v1.2.4

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(token string, filename string) (err error)

Delete removes a file from storage

func (*S3Storage) Get

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

Get retrieves a file from storage

func (*S3Storage) Head

func (s *S3Storage) Head(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 added in v1.2.0

func (s *S3Storage) Purge(days time.Duration) (err error)

Purge cleans up the storage

func (*S3Storage) Put

func (s *S3Storage) Put(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(token string, filename string) (reader io.ReadCloser, contentLength uint64, err error)
	// Head retrieves content length of a file from storage
	Head(token string, filename string) (contentLength uint64, err error)
	// Put saves a file on storage
	Put(token string, filename string, reader io.Reader, contentType string, contentLength uint64) error
	// Delete removes a file from storage
	Delete(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(days time.Duration) error

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

Storage is the interface for storage operation

type StorjStorage added in v1.2.0

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

StorjStorage is a storage backed by Storj

func NewStorjStorage added in v1.2.0

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

NewStorjStorage is the factory for StorjStorage

func (*StorjStorage) Delete added in v1.2.0

func (s *StorjStorage) Delete(token string, filename string) (err error)

Delete removes a file from storage

func (*StorjStorage) Get added in v1.2.0

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

Get retrieves a file from storage

func (*StorjStorage) Head added in v1.2.0

func (s *StorjStorage) Head(token string, filename string) (contentLength uint64, err error)

Head retrieves content length of a file from storage

func (*StorjStorage) IsNotExist added in v1.2.0

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

IsNotExist indicates if a file doesn't exist on storage

func (*StorjStorage) Purge added in v1.2.0

func (s *StorjStorage) Purge(days time.Duration) (err error)

Purge cleans up the storage

func (*StorjStorage) Put added in v1.2.0

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

Put saves a file on storage

func (*StorjStorage) Type added in v1.2.0

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