internal

package
v0.0.0-...-18d4e17 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2022 License: MIT Imports: 63 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// InvalidConfigValue is the constant value for invalid config values
	// which must be changed for production configurations before successful
	// startup
	InvalidConfigValue = "INVALID CONFIG VALUE - PLEASE CHANGE THIS VALUE"

	// DebugMode is the default debug mode
	DefaultDebug = false

	// DefaultData is the default data directory for storage
	DefaultData = "./data"

	// DefaultStore is the default data store used for accounts, sessions, etc
	DefaultStore = "bitcask://spyda.db"

	// DefaultBaseURL is the default Base URL for the app used to construct feed URLs
	DefaultBaseURL = "http://0.0.0.0:8000"

	// DefaultAdminXXX is the default admin user / operator
	DefaultAdminName  = "Administrator"
	DefaultAdminEmail = "support@spyda.dev"

	// DefaultName is the default instance name
	DefaultName = "spyda.dev"

	// DefaultMetaxxx are the default set of <meta> tags used on non-specific views
	DefaultMetaTitle       = ""
	DefaultMetaAuthor      = "spyda.dev"
	DefaultMetaKeywords    = "spider, crawler, search, engine, web, index, spyda, find, lookup"
	DefaultMetaDescription = " 🕸 spyda is a privacy first search engine and web crawler."

	// DefaultTheme is the default theme to use ('light' or 'dark')
	DefaultTheme = "dark"

	// DefaultCookieSecret is the server's default cookie secret
	DefaultCookieSecret = InvalidConfigValue

	// DefaultResultsPerPage is the server's default results per page to display
	DefaultResultsPerPage = 10

	// DefaultSessionExpiry is the server's default session expiry time
	DefaultSessionExpiry = 240 * time.Hour // 10 days

	// Default SMTP configuration
	DefaultSMTPHost = "smtp.gmail.com"
	DefaultSMTPPort = 587
	DefaultSMTPUser = InvalidConfigValue
	DefaultSMTPPass = InvalidConfigValue
	DefaultSMTPFrom = InvalidConfigValue
)
View Source
const (
	CacheDir = "cache"

	DayAgo   = time.Hour * 24
	WeekAgo  = DayAgo * 7
	MonthAgo = DayAgo * 30
	YearAgo  = MonthAgo * 12

	URLHashLength = 15
)
View Source
const (
	MaxFailedLogins = 3 // By default 3 failed login attempts per 5 minutes
)
View Source
const OpenSearchTemplate string = `` /* 308-byte string literal not displayed */

Variables

View Source
var (
	Jobs        map[string]JobSpec
	StartupJobs map[string]JobSpec
)
View Source
var (
	ErrInvalidStore = errors.New("error: invalid store")
	ErrURLNotFound  = errors.New("error: url not found")
)
View Source
var (
	ErrBadRequest       = errors.New("error: request failed with non-200 response")
	ErrInvalidUsername  = errors.New("error: invalid username")
	ErrUsernameTooLong  = errors.New("error: username is too long")
	ErrReservedUsername = errors.New("error: username is reserved")
)
View Source
var (
	// DefaultSearchPrompts are the set of default prompts for search(s)
	DefaultSearchPrompts = []string{
		`What can we find for you today?`,
		`Whatcha look'n for?`,
		`Looking for something? Type some keywords and hit Go!`,
		`Looking for a local buinsess? Find it here!`,
		`Tired of search engines tracking you? Search freely and privately here!`,
		`Search the web...`,
	}
)
View Source
var (
	ErrConfigPathMissing = errors.New("error: config file missing")
)
View Source
var (
	ErrInvalidURL = errors.New("error: invalid or empty URL")
)
View Source
var (
	ErrSendingEmail = errors.New("error: unable to send email")
)

Functions

func CmdExists

func CmdExists(cmd string) bool

CmdExists ...

func FastHash

func FastHash(s string) string

func FileExists

func FileExists(name string) bool
func FindLinks(url string) chan string

func FormatForDateTime

func FormatForDateTime(t time.Time) string

func FormatRequest

func FormatRequest(r *http.Request) string

FormatRequest generates ascii representation of a request

func GenerateRandomToken

func GenerateRandomToken() string
func GetLinks(url string) (links chan string, err error)

func HasString

func HasString(a []string, x string) bool

func HashURL

func HashURL(url string) string

func HostnameFromURL

func HostnameFromURL(uri string) string

func Indent

func Indent(text, indent string) string

indents a block of text with an indent string

func IntPow

func IntPow(x, y int) int

func IsLocalURLFactory

func IsLocalURLFactory(conf *Config) func(url string) bool

func MapStrings

func MapStrings(xs []string, f func(s string) string) []string

func NewStats

func NewStats(name string) *expvar.Map

NewStats ...

func NewSyncStoreJob

func NewSyncStoreJob(conf *Config, db Store) cron.Job

func NormalizeURL

func NormalizeURL(url string) string

func NormalizeUsername

func NormalizeUsername(username string) string

func PrettyURL

func PrettyURL(uri string) string

func RedirectRefererURL

func RedirectRefererURL(r *http.Request, conf *Config, defaultURL string) string

RedirectRefererURL constructs a Redirect URL from the given Request URL and possibly Referer, if the Referer's Base URL matches the Server's Base URL will return the Referer URL otherwise the defaultURL. This is primarily used to redirect a user from a successful /login back to the page they were on.

func RemoveString

func RemoveString(xs []string, e string) []string

func RenderHTML

func RenderHTML(tpl string, ctx *Context) (string, error)

RenderHTML ...

func RenderString

func RenderString(tpl string, ctx *Context) (string, error)

RenderString ...

func Request

func Request(conf *Config, method, url string, headers http.Header) (*http.Response, error)

func ResourceExists

func ResourceExists(conf *Config, url string) bool

func RunCmd

func RunCmd(timeout time.Duration, command string, args ...string) error

RunCmd ...

func SafeParseInt

func SafeParseInt(s string, d int) int

SafeParseInt ...

func SendEmail

func SendEmail(conf *Config, recipients []string, replyTo, subject string, body string) error

func SendSupportRequestEmail

func SendSupportRequestEmail(conf *Config, name, email, subject, message string) error

func Slugify

func Slugify(uri string) string

func StringKeys

func StringKeys(kv map[string]string) []string

func StringValues

func StringValues(kv map[string]string) []string

func URLForCached

func URLForCached(baseURL, hash string) string

func URLForPage

func URLForPage(baseURL, page string) string

func URLForTask

func URLForTask(baseURL, uuid string) string

func UniqStrings

func UniqStrings(xs []string) []string

func ValidateUsername

func ValidateUsername(username string) error

ValidateUsername validates the username before allowing it to be created. This ensures usernames match a defined pattern and that some usernames that are reserved are never used by users.

Types

type BaseTask

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

func NewBaseTask

func NewBaseTask() *BaseTask

func (*BaseTask) Done

func (t *BaseTask) Done()

func (*BaseTask) Error

func (t *BaseTask) Error() error

func (*BaseTask) Fail

func (t *BaseTask) Fail(err error) error

func (*BaseTask) ID

func (t *BaseTask) ID() string

func (*BaseTask) Result

func (t *BaseTask) Result() TaskResult

func (*BaseTask) SetData

func (t *BaseTask) SetData(key, val string)

func (*BaseTask) SetState

func (t *BaseTask) SetState(state TaskState)

func (*BaseTask) State

func (t *BaseTask) State() TaskState

func (*BaseTask) String

func (t *BaseTask) String() string

type BitcaskStore

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

BitcaskStore ...

func (*BitcaskStore) Close

func (bs *BitcaskStore) Close() error

Close ...

func (*BitcaskStore) DelURL

func (bs *BitcaskStore) DelURL(hash string) error

func (*BitcaskStore) ForEachURL

func (bs *BitcaskStore) ForEachURL(f func(url *URL) error) error

func (*BitcaskStore) GetURL

func (bs *BitcaskStore) GetURL(hash string) (*URL, error)

func (*BitcaskStore) HasURL

func (bs *BitcaskStore) HasURL(hash string) bool

func (*BitcaskStore) Merge

func (bs *BitcaskStore) Merge() error

Merge ...

func (*BitcaskStore) SetURL

func (bs *BitcaskStore) SetURL(hash string, url *URL) error

func (*BitcaskStore) Sync

func (bs *BitcaskStore) Sync() error

Sync ...

func (*BitcaskStore) URLCount

func (bs *BitcaskStore) URLCount() int64

type CachedItem

type CachedItem struct {
	Value  int
	Expiry time.Time
}

func (CachedItem) Expired

func (item CachedItem) Expired() bool

type CachedItems

type CachedItems map[string]CachedItem

type Config

type Config struct {
	Debug bool

	Data        string
	Name        string
	Description string
	Store       string
	Theme       string
	BaseURL     string
	AdminName   string
	AdminEmail  string

	SearchPrompts  []string
	ResultsPerPage int

	SessionExpiry time.Duration

	CookieSecret string

	SMTPHost string
	SMTPPort int
	SMTPUser string
	SMTPPass string
	SMTPFrom string
	// contains filtered or unexported fields
}

Config contains the server configuration parameters

func NewConfig

func NewConfig() *Config

func (*Config) IsLocalURL

func (c *Config) IsLocalURL(url string) bool

func (*Config) LocalURL

func (c *Config) LocalURL() *url.URL

func (*Config) RandomSearchPrompt

func (c *Config) RandomSearchPrompt() string

RandomSearchPrompt returns a random Search Prompt for display by the UI

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration is valid which for the most part just ensures that default secrets are actually configured correctly

type Context

type Context struct {
	Config string

	Debug bool

	BaseURL         string
	InstanceName    string
	SoftwareVersion string

	SearchQuery  string
	SearchPrompt string

	Username      string
	User          *User
	Tokens        []*Token
	Authenticated bool
	IsAdmin       bool

	Error   bool
	Message string
	Theme   string
	Commit  string

	Page    string
	Content template.HTML

	Title string
	Meta  Meta

	CachedURL     string
	CachedTitle   string
	CachedContent string

	SearchTook time.Duration
	Results    Results
	Pager      *paginator.Paginator

	// Reset Password Token
	PasswordResetToken string

	// CSRF Token
	CSRFToken string
}

func NewContext

func NewContext(conf *Config, db Store, req *http.Request) *Context

type CrawlTask

type CrawlTask struct {
	*BaseTask
	// contains filtered or unexported fields
}

func NewCrawlTask

func NewCrawlTask(conf *Config, db Store, indexer Indexer, url string) *CrawlTask

func (*CrawlTask) Run

func (t *CrawlTask) Run() error

func (*CrawlTask) String

func (t *CrawlTask) String() string

type Crawler

type Crawler interface {
	Start()
	Stop()
	Crawl(url string) error
}

func NewCrawler

func NewCrawler(conf *Config, tasks *Dispatcher, db Store, indexer Indexer) (Crawler, error)

type Dispatcher

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

Dispatcher maintains a pool for available workers and a task queue that workers will process

func NewDispatcher

func NewDispatcher(maxWorkers int, maxQueue int) *Dispatcher

NewDispatcher creates a new dispatcher with the given number of workers and buffers the task queue based on maxQueue. It also initializes the channels for the worker pool and task queue

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(task Task) (string, error)

Dispatch pushes the given task into the task queue. The first available worker will perform the task

func (*Dispatcher) DispatchFunc

func (d *Dispatcher) DispatchFunc(f func() error) (string, error)

DispatchFunc pushes the given func into the task queue by first wrapping it with a `TaskFunc` task.

func (*Dispatcher) Lookup

func (d *Dispatcher) Lookup(id string) (Task, bool)

Lookup returns the matching `Task` given its id

func (*Dispatcher) Start

func (d *Dispatcher) Start()

Start creates and starts workers, adding them to the worker pool. Then, it starts a select loop to wait for tasks to be dispatched to available workers

func (*Dispatcher) Stop

func (d *Dispatcher) Stop()

Stop ends execution for all workers and closes all channels, then removes all workers

func (*Dispatcher) Tasks

func (d *Dispatcher) Tasks() map[string]TaskResult

Tasks returns all tasks

type Entry

type Entry struct {
	URL         string
	Title       string
	Author      string
	Summary     string
	Content     string
	HTMLContent string
	Length      int
	// contains filtered or unexported fields
}

Entry ...

func LoadEntry

func LoadEntry(data []byte) (entry *Entry, err error)

func Scrape

func Scrape(conf *Config, url string) (*Entry, error)

func (*Entry) Bytes

func (e *Entry) Bytes() ([]byte, error)

func (*Entry) Hash

func (e *Entry) Hash() string

func (*Entry) String

func (e *Entry) String() string

type ErrAudioUploadFailed

type ErrAudioUploadFailed struct {
	Err error
}

func (*ErrAudioUploadFailed) Error

func (e *ErrAudioUploadFailed) Error() string

func (*ErrAudioUploadFailed) Unwrap

func (e *ErrAudioUploadFailed) Unwrap() error

type ErrCommandFailed

type ErrCommandFailed struct {
	Err    error
	Status int
}

func (*ErrCommandFailed) Error

func (e *ErrCommandFailed) Error() string

func (*ErrCommandFailed) Is

func (e *ErrCommandFailed) Is(target error) bool

func (*ErrCommandFailed) Unwrap

func (e *ErrCommandFailed) Unwrap() error

type ErrCommandKilled

type ErrCommandKilled struct {
	Err    error
	Signal syscall.Signal
}

func (*ErrCommandKilled) Error

func (e *ErrCommandKilled) Error() string

func (*ErrCommandKilled) Is

func (e *ErrCommandKilled) Is(target error) bool

func (*ErrCommandKilled) Unwrap

func (e *ErrCommandKilled) Unwrap() error

type ErrTranscodeFailed

type ErrTranscodeFailed struct {
	Err error
}

func (*ErrTranscodeFailed) Error

func (e *ErrTranscodeFailed) Error() string

func (*ErrTranscodeFailed) Unwrap

func (e *ErrTranscodeFailed) Unwrap() error

type ErrTranscodeTimeout

type ErrTranscodeTimeout struct {
	Err error
}

func (*ErrTranscodeTimeout) Error

func (e *ErrTranscodeTimeout) Error() string

func (*ErrTranscodeTimeout) Unwrap

func (e *ErrTranscodeTimeout) Unwrap() error

type ErrVideoUploadFailed

type ErrVideoUploadFailed struct {
	Err error
}

func (*ErrVideoUploadFailed) Error

func (e *ErrVideoUploadFailed) Error() string

func (*ErrVideoUploadFailed) Unwrap

func (e *ErrVideoUploadFailed) Unwrap() error

type FrontMatter

type FrontMatter struct {
	Title       string
	Description string
}

type FuncTask

type FuncTask struct {
	*BaseTask
	// contains filtered or unexported fields
}

func NewFuncTask

func NewFuncTask(f func() error) *FuncTask

func (*FuncTask) Run

func (t *FuncTask) Run() error

func (*FuncTask) String

func (t *FuncTask) String() string

type Indexer

type Indexer interface {
	Index(entry *Entry) error
	Size() int64
	Search(q string, p int) (*bleve.SearchResult, error)
}

func NewIndexer

func NewIndexer(conf *Config) (Indexer, error)

type IntAdapter

type IntAdapter struct {
	N int
}

func (IntAdapter) Nums

func (a IntAdapter) Nums() int

func (IntAdapter) Slice

func (a IntAdapter) Slice(offset, length int, data interface{}) error

type JobFactory

type JobFactory func(conf *Config, store Store) cron.Job

type JobSpec

type JobSpec struct {
	Schedule string
	Factory  JobFactory
}

JobSpec ...

func NewJobSpec

func NewJobSpec(schedule string, factory JobFactory) JobSpec

type Meta

type Meta struct {
	Title       string
	Description string
	UpdatedAt   string
	Image       string
	Author      string
	URL         string
	Keywords    string
}

type Middleware

type Middleware func(httprouter.Handle) httprouter.Handle

Middleware ...

type Option

type Option func(*Config) error

Option is a function that takes a config struct and modifies it

func WithAdminEmail

func WithAdminEmail(adminEmail string) Option

WithAdminEmail sets the Admin email used to contact the operator

func WithAdminName

func WithAdminName(adminName string) Option

WithAdminName sets the Admin name used to identify the operator

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL sets the Base URL used for constructing feed URLs

func WithCookieSecret

func WithCookieSecret(secret string) Option

WithCookieSecret sets the server's cookie secret

func WithData

func WithData(data string) Option

WithData sets the data directory to use for storage

func WithDebug

func WithDebug(debug bool) Option

WithDebug sets the debug mode lfag

func WithDescription

func WithDescription(description string) Option

WithDescription sets the instance's description

func WithName

func WithName(name string) Option

WithName sets the instance's name

func WithResultsPerPage

func WithResultsPerPage(resultsPerPage int) Option

WithResultsPerPage sets the server's results per page

func WithSMTPFrom

func WithSMTPFrom(from string) Option

WithSMTPFrom sets the SMTPFrom address to use for sending email

func WithSMTPHost

func WithSMTPHost(host string) Option

WithSMTPHost sets the SMTPHost to use for sending email

func WithSMTPPass

func WithSMTPPass(pass string) Option

WithSMTPPass sets the SMTPPass to use for sending email

func WithSMTPPort

func WithSMTPPort(port int) Option

WithSMTPPort sets the SMTPPort to use for sending email

func WithSMTPUser

func WithSMTPUser(user string) Option

WithSMTPUser sets the SMTPUser to use for sending email

func WithSessionExpiry

func WithSessionExpiry(expiry time.Duration) Option

WithSessionExpiry sets the server's session expiry time

func WithStore

func WithStore(store string) Option

WithStore sets the store to use for accounts, sessions, etc.

func WithTheme

func WithTheme(theme string) Option

WithTheme sets the default theme to use

type Page

type Page struct {
	Content      string
	LastModified time.Time
}

type Result

type Result struct {
	ID      string
	URL     string
	Title   string
	Summary template.HTML
	Length  int
}

type Results

type Results []Result

type Router

type Router struct {
	httprouter.Router
	// contains filtered or unexported fields
}

Router ...

func NewRouter

func NewRouter() *Router

NewRouter ...

func (*Router) DELETE

func (r *Router) DELETE(path string, handle httprouter.Handle)

DELETE is a shortcut for Router.Handle("DELETE", path, handle)

func (*Router) File

func (r *Router) File(path, name string)

File serves the named file.

func (*Router) GET

func (r *Router) GET(path string, handle httprouter.Handle)

GET is a shortcut for Router.Handle("GET", path, handle)

func (*Router) Group

func (r *Router) Group(path string, m ...Middleware) *Router

Group returns new *Router with given path and middlewares. It should be used for handles which have same path prefix or common middlewares.

func (*Router) HEAD

func (r *Router) HEAD(path string, handle httprouter.Handle)

HEAD is a shortcut for Router.Handle("HEAD", path, handle)

func (*Router) Handle

func (r *Router) Handle(method, path string, handle httprouter.Handle)

Handle registers a new request handle combined with middlewares.

func (*Router) Handler

func (r *Router) Handler(method, path string, handler http.Handler)

Handler is an adapter for http.Handler.

func (*Router) HandlerFunc

func (r *Router) HandlerFunc(method, path string, handler http.HandlerFunc)

HandlerFunc is an adapter for http.HandlerFunc.

func (*Router) OPTIONS

func (r *Router) OPTIONS(path string, handle httprouter.Handle)

OPTIONS is a shortcut for Router.Handle("OPTIONS", path, handle)

func (*Router) PATCH

func (r *Router) PATCH(path string, handle httprouter.Handle)

PATCH is a shortcut for Router.Handle("PATCH", path, handle)

func (*Router) POST

func (r *Router) POST(path string, handle httprouter.Handle)

POST is a shortcut for Router.Handle("POST", path, handle)

func (*Router) PUT

func (r *Router) PUT(path string, handle httprouter.Handle)

PUT is a shortcut for Router.Handle("PUT", path, handle)

func (*Router) ServeFilesWithCacheControl

func (r *Router) ServeFilesWithCacheControl(path string, root http.FileSystem)

ServeFilesWithCacheControl ...

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Router) Static

func (r *Router) Static(path, root string)

Static serves files from given root directory.

func (*Router) Use

func (r *Router) Use(m ...Middleware) *Router

Use appends new middleware to current Router.

type Server

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

Server ...

func NewServer

func NewServer(bind string, options ...Option) (*Server, error)

NewServer ...

func (*Server) AddCronJob

func (s *Server) AddCronJob(spec string, job cron.Job) error

AddCronJob ...

func (*Server) AddHandler

func (s *Server) AddHandler() httprouter.Handle

AddHandler ...

func (*Server) AddRoute

func (s *Server) AddRoute(method, path string, handler http.Handler)

AddRouter ...

func (*Server) AddShutdownHook

func (s *Server) AddShutdownHook(f func())

AddShutdownHook ...

func (*Server) CacheHandler

func (s *Server) CacheHandler() httprouter.Handle

CacheHandler ...

func (*Server) CaptchaHandler

func (s *Server) CaptchaHandler() httprouter.Handle

CaptchaHandler ...

func (*Server) IndexHandler

func (s *Server) IndexHandler() httprouter.Handle

IndexHandler ...

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe ...

func (*Server) NotFoundHandler

func (s *Server) NotFoundHandler(w http.ResponseWriter, r *http.Request)

func (*Server) OpenSearchHandler

func (s *Server) OpenSearchHandler() httprouter.Handle

OpenSearchHandler ...

func (*Server) PageHandler

func (s *Server) PageHandler(name string) httprouter.Handle

PageHandler ...

func (*Server) RobotsHandler

func (s *Server) RobotsHandler() httprouter.Handle

RobotsHandler ...

func (*Server) Run

func (s *Server) Run() (err error)

Run ...

func (*Server) SearchHandler

func (s *Server) SearchHandler() httprouter.Handle

SearchHandler ...

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown ...

func (*Server) SupportHandler

func (s *Server) SupportHandler() httprouter.Handle

SupportHandler ...

func (*Server) TaskHandler

func (s *Server) TaskHandler() httprouter.Handle

TaskHandler ...

func (*Server) TasksHandler

func (s *Server) TasksHandler() httprouter.Handle

TasksHandler ...

type Store

type Store interface {
	Merge() error
	Close() error
	Sync() error

	DelURL(hash string) error
	HasURL(hash string) bool
	GetURL(hash string) (*URL, error)
	SetURL(hash string, url *URL) error
	URLCount() int64
	ForEachURL(f func(*URL) error) error
}

func NewStore

func NewStore(store string) (Store, error)

type SupportRequestEmailContext

type SupportRequestEmailContext struct {
	Instance string

	Name    string
	Email   string
	Subject string
	Message string
}

type SyncStoreJob

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

func (*SyncStoreJob) Run

func (job *SyncStoreJob) Run()

type TTLCache

type TTLCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewTTLCache

func NewTTLCache(ttl time.Duration) *TTLCache

func (*TTLCache) Dec

func (cache *TTLCache) Dec(k string) int

func (*TTLCache) Get

func (cache *TTLCache) Get(k string) int

func (*TTLCache) Inc

func (cache *TTLCache) Inc(k string) int

func (*TTLCache) Reset

func (cache *TTLCache) Reset(k string) int

func (*TTLCache) Set

func (cache *TTLCache) Set(k string, v int) int

type Task

type Task interface {
	fmt.Stringer

	ID() string
	State() TaskState
	Result() TaskResult
	Error() error
	Run() error
}

Task is an interface that represents a single task to be executed by a worker. Any object can implement a `Task` if it implements the interface.

type TaskData

type TaskData map[string]string

type TaskResult

type TaskResult struct {
	State string   `json:"state"`
	Error string   `json:"error"`
	Data  TaskData `json:"data"`
}

type TaskState

type TaskState int
const (
	TaskStatePending TaskState = iota
	TaskStateRunning
	TaskStateComplete
	TaskStateFailed
)

func (TaskState) String

func (t TaskState) String() string

type TemplateManager

type TemplateManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewTemplateManager

func NewTemplateManager(conf *Config) (*TemplateManager, error)

func (*TemplateManager) Add

func (m *TemplateManager) Add(name string, template *template.Template)

func (*TemplateManager) Exec

func (m *TemplateManager) Exec(name string, ctx *Context) (io.WriterTo, error)

func (*TemplateManager) LoadTemplates

func (m *TemplateManager) LoadTemplates() error

type TimeVar

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

TimeVar ...

func (*TimeVar) Add

func (o *TimeVar) Add(duration time.Duration)

Add ...

func (*TimeVar) Set

func (o *TimeVar) Set(date time.Time)

Set ...

func (*TimeVar) String

func (o *TimeVar) String() string

String ...

type Token

type Token struct {
	Signature string
	Value     string
	UserAgent string
	CreatedAt time.Time
	ExpiresAt time.Time
}

Token ...

func LoadToken

func LoadToken(data []byte) (token *Token, err error)

func (*Token) Bytes

func (t *Token) Bytes() ([]byte, error)

type URI

type URI struct {
	Type string
	Path string
}

func ParseURI

func ParseURI(uri string) (*URI, error)

func (URI) IsZero

func (u URI) IsZero() bool

func (URI) String

func (u URI) String() string

type URL

type URL struct {
	URL       string
	CrawledAt time.Time
	ExpiresAt time.Time
	// contains filtered or unexported fields
}

URL ...

func LoadURL

func LoadURL(data []byte) (u *URL, err error)

func NewURL

func NewURL(url string) *URL

NewURL ...

func (*URL) Bytes

func (u *URL) Bytes() ([]byte, error)

func (*URL) Hash

func (u *URL) Hash() string

func (*URL) String

func (u *URL) String() string

type User

type User struct {
	Username  string
	Password  string
	CreatedAt time.Time

	Recovery string `default:"auto"`

	Tokens []string `default:"[]"`
}

User ...

func LoadUser

func LoadUser(data []byte) (user *User, err error)

func NewUser

func NewUser() *User

NewUser ...

func (*User) AddToken

func (u *User) AddToken(token *Token)

HasToken will add a token to a user if it doesn't exist already

func (*User) Bytes

func (u *User) Bytes() ([]byte, error)

func (*User) HasToken

func (u *User) HasToken(token string) bool

HasToken will compare a token value with stored tokens

func (*User) String

func (u *User) String() string

type Worker

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

Worker attaches to a provided worker pool, and looks for tasks on its task channel

func NewWorker

func NewWorker(workerPool chan chan Task) *Worker

NewWorker creates a new worker using the given id and attaches to the provided worker pool. It also initializes the task/quit channels

func (*Worker) Start

func (w *Worker) Start()

Start initializes a select loop to listen for tasks to execute

func (*Worker) Stop

func (w *Worker) Stop()

Stop will end the task select loop for the worker

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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