provider

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MetadataDirectoryName directory when metadata are stored
	MetadataDirectoryName = ".fibr"
)

Variables

View Source
var (
	// ArchiveExtensions contains extensions of Archive
	ArchiveExtensions = map[string]bool{".zip": true, ".tar": true, ".gz": true, ".rar": true}
	// AudioExtensions contains extensions of Audio
	AudioExtensions = map[string]bool{".mp3": true}
	// CodeExtensions contains extensions of Code
	CodeExtensions = map[string]bool{".html": true, ".css": true, ".js": true, ".jsx": true, ".json": true, ".yml": true, ".yaml": true, ".toml": true, ".md": true, ".go": true, ".py": true, ".java": true, ".xml": true}
	// ExcelExtensions contains extensions of Excel
	ExcelExtensions = map[string]bool{".xls": true, ".xlsx": true, ".xlsm": true}
	// ImageExtensions contains extensions of Image
	ImageExtensions = map[string]bool{".jpg": true, ".jpeg": true, ".png": true, ".gif": true, ".svg": true, ".tiff": true}
	// PdfExtensions contains extensions of Pdf
	PdfExtensions = map[string]bool{".pdf": true}
	// VideoExtensions contains extensions of Video
	VideoExtensions = map[string]string{".mp4": "video/mp4", ".mov": "video/quicktime", ".avi": "video/x-msvideo"}
	// WordExtensions contains extensions of Word
	WordExtensions = map[string]bool{".doc": true, ".docx": true, ".docm": true}
)

Functions

func ErrNotExist

func ErrNotExist(err error) error

ErrNotExist create a NotExist error

func FindIndex

func FindIndex(arr []string, value string) int

FindIndex finds index of given value into array, or -1 if not found

func GetPathname

func GetPathname(folder, name string, share Share) string

GetPathname computes pathname for given params

func GetURI

func GetURI(folder, name string, share Share) string

GetURI computes public URI for given params

func IsNotExist

func IsNotExist(err error) bool

IsNotExist checks if error match a not found

func RemoveIndex

func RemoveIndex(arr []string, index int) []string

RemoveIndex removes element at given index, if valid

func SafeWrite

func SafeWrite(w io.Writer, content string)

SafeWrite writes content to writer with error handling

func SanitizeName

func SanitizeName(name string, removeSlash bool) (string, error)

SanitizeName return sanitized name (remove diacritics)

Types

type Config

type Config struct {
	PublicURL string
	Version   string
	Seo       Seo
}

Config data

type Error

type Error struct {
	Err    error
	Status int
}

Error rendered to user

func NewError

func NewError(status int, err error) *Error

NewError create an http error

func (Error) Error

func (e Error) Error() string

Error convert error to string

type Page

type Page struct {
	Content map[string]interface{}

	Config  Config
	Request Request

	Message renderer.Message
	Error   *Error

	Layout      string
	PublicURL   string
	Title       string
	Description string
}

Page renderer to user

type PageBuilder

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

PageBuilder for interactively create page

func (*PageBuilder) Build

func (p *PageBuilder) Build() Page

Build Page Object

func (*PageBuilder) Config

func (p *PageBuilder) Config(config Config) *PageBuilder

Config set Config for page

func (*PageBuilder) Content

func (p *PageBuilder) Content(content map[string]interface{}) *PageBuilder

Content set content for page

func (*PageBuilder) Error

func (p *PageBuilder) Error(error *Error) *PageBuilder

Error set Error for page

func (*PageBuilder) Layout

func (p *PageBuilder) Layout(layout string) *PageBuilder

Layout set Layout for page

func (*PageBuilder) Message

func (p *PageBuilder) Message(message renderer.Message) *PageBuilder

Message set Message for page

func (*PageBuilder) Request

func (p *PageBuilder) Request(request Request) *PageBuilder

Request set Request for page

type Preferences

type Preferences struct {
	ListLayoutPath []string
}

Preferences holds preferences of the user

type ReadSeekerCloser

type ReadSeekerCloser interface {
	Read([]byte) (int, error)
	Seek(int64, int) (int64, error)
	Close() error
}

ReadSeekerCloser is a combination of io.Reader, io.Seeker and io.Closer

type RenderItem

type RenderItem struct {
	ID  string
	URI string
	StorageItem
}

RenderItem is a storage item with an id

type Renderer

type Renderer interface {
	Directory(http.ResponseWriter, Request, map[string]interface{}, renderer.Message)
	File(http.ResponseWriter, Request, map[string]interface{}, renderer.Message)
	Error(http.ResponseWriter, Request, *Error)
	Sitemap(http.ResponseWriter)
	SVG(http.ResponseWriter, string, string)
}

Renderer interface for return rich content to user

type Request

type Request struct {
	Share       Share
	CanShare    bool
	CanEdit     bool
	Path        string
	Display     string
	Preferences Preferences
}

Request from user

func (Request) GetFilepath

func (r Request) GetFilepath(name string) string

GetFilepath of request

func (Request) GetURI

func (r Request) GetURI(name string) string

GetURI of request

func (Request) Layout

func (r Request) Layout(name string) string

Layout returns layout of given name based on preferences

func (Request) LayoutPath

func (r Request) LayoutPath(path string) string

LayoutPath returns layout of given path based on preferences

type Seo

type Seo struct {
	Title       string
	Description string
	Img         string
	ImgHeight   uint
	ImgWidth    uint
}

Seo data

type Share

type Share struct {
	ID       string        `json:"id"`
	Path     string        `json:"path"`
	RootName string        `json:"rootName"`
	Password string        `json:"password"`
	Edit     bool          `json:"edit"`
	File     bool          `json:"file"`
	Creation time.Time     `json:"creation"`
	Duration time.Duration `json:"duration"`
}

Share stores informations about shared paths

func (Share) CheckPassword

func (s Share) CheckPassword(authorizationHeader string) error

CheckPassword verifies that request has correct password for share

type Storage

type Storage interface {
	SetIgnoreFn(ignoreFn func(StorageItem) bool)
	Info(pathname string) (StorageItem, error)
	Semaphore(pathname string) (bool, error)
	List(pathname string) ([]StorageItem, error)
	WriterTo(pathname string) (io.WriteCloser, error)
	ReaderFrom(pathname string) (ReadSeekerCloser, error)
	Walk(pathname string, walkFn func(StorageItem, error) error) error
	CreateDir(pathname string) error
	Store(pathname string, content io.ReadCloser) error
	Rename(oldName, newName string) error
	Remove(pathname string) error
}

Storage describe action on a storage provider

type StorageItem

type StorageItem struct {
	Info     interface{}
	Date     time.Time
	Pathname string
	Name     string

	IsDir bool
}

StorageItem describe item on a storage provider

func (StorageItem) Extension

func (s StorageItem) Extension() string

Extension gives extensions of item

func (StorageItem) IsImage

func (s StorageItem) IsImage() bool

IsImage determine if item if an image

func (StorageItem) IsPdf

func (s StorageItem) IsPdf() bool

IsPdf determine if item if a pdf

func (StorageItem) IsVideo

func (s StorageItem) IsVideo() bool

IsVideo determine if item if a video

func (StorageItem) Mime

func (s StorageItem) Mime() string

Mime gives Mime Type of item

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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