Documentation ¶
Index ¶
- Constants
- Variables
- func CmdExists(cmd string) bool
- func FastHash(s string) string
- func FileExists(name string) bool
- func FindLinks(url string) chan string
- func FormatForDateTime(t time.Time) string
- func FormatRequest(r *http.Request) string
- func GenerateRandomToken() string
- func GetLinks(url string) (links chan string, err error)
- func HasString(a []string, x string) bool
- func HashURL(url string) string
- func HostnameFromURL(uri string) string
- func Indent(text, indent string) string
- func IntPow(x, y int) int
- func IsLocalURLFactory(conf *Config) func(url string) bool
- func MapStrings(xs []string, f func(s string) string) []string
- func NewStats(name string) *expvar.Map
- func NewSyncStoreJob(conf *Config, db Store) cron.Job
- func NormalizeURL(url string) string
- func NormalizeUsername(username string) string
- func PrettyURL(uri string) string
- func RedirectRefererURL(r *http.Request, conf *Config, defaultURL string) string
- func RemoveString(xs []string, e string) []string
- func RenderHTML(tpl string, ctx *Context) (string, error)
- func RenderString(tpl string, ctx *Context) (string, error)
- func Request(conf *Config, method, url string, headers http.Header) (*http.Response, error)
- func ResourceExists(conf *Config, url string) bool
- func RunCmd(timeout time.Duration, command string, args ...string) error
- func SafeParseInt(s string, d int) int
- func SendEmail(conf *Config, recipients []string, replyTo, subject string, body string) error
- func SendSupportRequestEmail(conf *Config, name, email, subject, message string) error
- func Slugify(uri string) string
- func StringKeys(kv map[string]string) []string
- func StringValues(kv map[string]string) []string
- func URLForCached(baseURL, hash string) string
- func URLForPage(baseURL, page string) string
- func URLForTask(baseURL, uuid string) string
- func UniqStrings(xs []string) []string
- func ValidateUsername(username string) error
- type BaseTask
- func (t *BaseTask) Done()
- func (t *BaseTask) Error() error
- func (t *BaseTask) Fail(err error) error
- func (t *BaseTask) ID() string
- func (t *BaseTask) Result() TaskResult
- func (t *BaseTask) SetData(key, val string)
- func (t *BaseTask) SetState(state TaskState)
- func (t *BaseTask) State() TaskState
- func (t *BaseTask) String() string
- type BitcaskStore
- func (bs *BitcaskStore) Close() error
- func (bs *BitcaskStore) DelURL(hash string) error
- func (bs *BitcaskStore) ForEachURL(f func(url *URL) error) error
- func (bs *BitcaskStore) GetURL(hash string) (*URL, error)
- func (bs *BitcaskStore) HasURL(hash string) bool
- func (bs *BitcaskStore) Merge() error
- func (bs *BitcaskStore) SetURL(hash string, url *URL) error
- func (bs *BitcaskStore) Sync() error
- func (bs *BitcaskStore) URLCount() int64
- type CachedItem
- type CachedItems
- type Config
- type Context
- type CrawlTask
- type Crawler
- type Dispatcher
- type Entry
- type ErrAudioUploadFailed
- type ErrCommandFailed
- type ErrCommandKilled
- type ErrTranscodeFailed
- type ErrTranscodeTimeout
- type ErrVideoUploadFailed
- type FrontMatter
- type FuncTask
- type Indexer
- type IntAdapter
- type JobFactory
- type JobSpec
- type Meta
- type Middleware
- type Option
- func WithAdminEmail(adminEmail string) Option
- func WithAdminName(adminName string) Option
- func WithBaseURL(baseURL string) Option
- func WithCookieSecret(secret string) Option
- func WithData(data string) Option
- func WithDebug(debug bool) Option
- func WithDescription(description string) Option
- func WithName(name string) Option
- func WithResultsPerPage(resultsPerPage int) Option
- func WithSMTPFrom(from string) Option
- func WithSMTPHost(host string) Option
- func WithSMTPPass(pass string) Option
- func WithSMTPPort(port int) Option
- func WithSMTPUser(user string) Option
- func WithSessionExpiry(expiry time.Duration) Option
- func WithStore(store string) Option
- func WithTheme(theme string) Option
- type Page
- type Result
- type Results
- type Router
- func (r *Router) DELETE(path string, handle httprouter.Handle)
- func (r *Router) File(path, name string)
- func (r *Router) GET(path string, handle httprouter.Handle)
- func (r *Router) Group(path string, m ...Middleware) *Router
- func (r *Router) HEAD(path string, handle httprouter.Handle)
- func (r *Router) Handle(method, path string, handle httprouter.Handle)
- func (r *Router) Handler(method, path string, handler http.Handler)
- func (r *Router) HandlerFunc(method, path string, handler http.HandlerFunc)
- func (r *Router) OPTIONS(path string, handle httprouter.Handle)
- func (r *Router) PATCH(path string, handle httprouter.Handle)
- func (r *Router) POST(path string, handle httprouter.Handle)
- func (r *Router) PUT(path string, handle httprouter.Handle)
- func (r *Router) ServeFilesWithCacheControl(path string, root http.FileSystem)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) Static(path, root string)
- func (r *Router) Use(m ...Middleware) *Router
- type Server
- func (s *Server) AddCronJob(spec string, job cron.Job) error
- func (s *Server) AddHandler() httprouter.Handle
- func (s *Server) AddRoute(method, path string, handler http.Handler)
- func (s *Server) AddShutdownHook(f func())
- func (s *Server) CacheHandler() httprouter.Handle
- func (s *Server) CaptchaHandler() httprouter.Handle
- func (s *Server) IndexHandler() httprouter.Handle
- func (s *Server) ListenAndServe() error
- func (s *Server) NotFoundHandler(w http.ResponseWriter, r *http.Request)
- func (s *Server) OpenSearchHandler() httprouter.Handle
- func (s *Server) PageHandler(name string) httprouter.Handle
- func (s *Server) RobotsHandler() httprouter.Handle
- func (s *Server) Run() (err error)
- func (s *Server) SearchHandler() httprouter.Handle
- func (s *Server) Shutdown(ctx context.Context) error
- func (s *Server) SupportHandler() httprouter.Handle
- func (s *Server) TaskHandler() httprouter.Handle
- func (s *Server) TasksHandler() httprouter.Handle
- type Store
- type SupportRequestEmailContext
- type SyncStoreJob
- type TTLCache
- type Task
- type TaskData
- type TaskResult
- type TaskState
- type TemplateManager
- type TimeVar
- type Token
- type URI
- type URL
- type User
- type Worker
Constants ¶
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 )
const ( CacheDir = "cache" DayAgo = time.Hour * 24 WeekAgo = DayAgo * 7 MonthAgo = DayAgo * 30 YearAgo = MonthAgo * 12 URLHashLength = 15 )
const (
MaxFailedLogins = 3 // By default 3 failed login attempts per 5 minutes
)
const OpenSearchTemplate string = `` /* 308-byte string literal not displayed */
Variables ¶
var ( Jobs map[string]JobSpec StartupJobs map[string]JobSpec )
var ( ErrInvalidStore = errors.New("error: invalid store") ErrURLNotFound = errors.New("error: url not found") )
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") )
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...`, } )
var (
ErrConfigPathMissing = errors.New("error: config file missing")
)
var (
ErrInvalidURL = errors.New("error: invalid or empty URL")
)
var (
ErrSendingEmail = errors.New("error: unable to send email")
)
Functions ¶
func FileExists ¶
func FormatForDateTime ¶
func FormatRequest ¶
FormatRequest generates ascii representation of a request
func GenerateRandomToken ¶
func GenerateRandomToken() string
func HostnameFromURL ¶
func IsLocalURLFactory ¶
func NormalizeURL ¶
func NormalizeUsername ¶
func RedirectRefererURL ¶
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 ResourceExists ¶
func SendSupportRequestEmail ¶
func StringKeys ¶
func StringValues ¶
func URLForCached ¶
func URLForPage ¶
func URLForTask ¶
func UniqStrings ¶
func ValidateUsername ¶
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) Result ¶
func (t *BaseTask) Result() TaskResult
type BitcaskStore ¶
type BitcaskStore struct {
// contains filtered or unexported fields
}
BitcaskStore ...
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) HasURL ¶
func (bs *BitcaskStore) HasURL(hash string) bool
func (*BitcaskStore) URLCount ¶
func (bs *BitcaskStore) URLCount() int64
type CachedItem ¶
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 (*Config) IsLocalURL ¶
func (*Config) RandomSearchPrompt ¶
RandomSearchPrompt returns a random Search Prompt for display by the UI
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 }
type CrawlTask ¶
type CrawlTask struct { *BaseTask // contains filtered or unexported fields }
func NewCrawlTask ¶
type Crawler ¶
func NewCrawler ¶
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 ...
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 ¶
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 ¶
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 FuncTask ¶
type FuncTask struct { *BaseTask // contains filtered or unexported fields }
func NewFuncTask ¶
type Indexer ¶
type Indexer interface { Index(entry *Entry) error Size() int64 Search(q string, p int) (*bleve.SearchResult, error) }
func NewIndexer ¶
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 JobSpec ¶
type JobSpec struct { Schedule string Factory JobFactory }
JobSpec ...
func NewJobSpec ¶
func NewJobSpec(schedule string, factory JobFactory) JobSpec
type Option ¶
Option is a function that takes a config struct and modifies it
func WithAdminEmail ¶
WithAdminEmail sets the Admin email used to contact the operator
func WithAdminName ¶
WithAdminName sets the Admin name used to identify the operator
func WithBaseURL ¶
WithBaseURL sets the Base URL used for constructing feed URLs
func WithCookieSecret ¶
WithCookieSecret sets the server's cookie secret
func WithDescription ¶
WithDescription sets the instance's description
func WithResultsPerPage ¶
WithResultsPerPage sets the server's results per page
func WithSMTPFrom ¶
WithSMTPFrom sets the SMTPFrom address to use for sending email
func WithSMTPHost ¶
WithSMTPHost sets the SMTPHost to use for sending email
func WithSMTPPass ¶
WithSMTPPass sets the SMTPPass to use for sending email
func WithSMTPPort ¶
WithSMTPPort sets the SMTPPort to use for sending email
func WithSMTPUser ¶
WithSMTPUser sets the SMTPUser to use for sending email
func WithSessionExpiry ¶
WithSessionExpiry sets the server's session expiry time
type Router ¶
type Router struct { httprouter.Router // contains filtered or unexported fields }
Router ...
func (*Router) DELETE ¶
func (r *Router) DELETE(path string, handle httprouter.Handle)
DELETE is a shortcut for Router.Handle("DELETE", path, handle)
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) 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) 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 (*Server) AddCronJob ¶
AddCronJob ...
func (*Server) CaptchaHandler ¶
func (s *Server) CaptchaHandler() httprouter.Handle
CaptchaHandler ...
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) SupportHandler ¶
func (s *Server) SupportHandler() httprouter.Handle
SupportHandler ...
type Store ¶
type SyncStoreJob ¶
type SyncStoreJob struct {
// contains filtered or unexported fields
}
func (*SyncStoreJob) Run ¶
func (job *SyncStoreJob) Run()
type TTLCache ¶
func NewTTLCache ¶
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 TaskResult ¶
type TemplateManager ¶
func NewTemplateManager ¶
func NewTemplateManager(conf *Config) (*TemplateManager, error)
func (*TemplateManager) Add ¶
func (m *TemplateManager) Add(name string, template *template.Template)
func (*TemplateManager) LoadTemplates ¶
func (m *TemplateManager) LoadTemplates() error
type Token ¶
type Token struct { Signature string Value string UserAgent string CreatedAt time.Time ExpiresAt time.Time }
Token ...
type URL ¶
type URL struct { URL string CrawledAt time.Time ExpiresAt time.Time // contains filtered or unexported fields }
URL ...
type User ¶
type User struct { Username string Password string CreatedAt time.Time Recovery string `default:"auto"` Tokens []string `default:"[]"` }
User ...
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 ¶
NewWorker creates a new worker using the given id and attaches to the provided worker pool. It also initializes the task/quit channels
Source Files ¶
- base_task.go
- bitcask_store.go
- config.go
- context.go
- crawl_task.go
- crawler.go
- dispatcher.go
- email.go
- entry.go
- errors.go
- func_task.go
- handlers.go
- indexer.go
- init.go
- jobs.go
- links.go
- models.go
- opensearch_handler.go
- options.go
- page_handlers.go
- paginator_adapters.go
- results.go
- robots.go
- router.go
- scraper.go
- server.go
- stats.go
- store.go
- support_handlers.go
- task.go
- task_handlers.go
- templates.go
- ttlcache.go
- utils.go
- worker.go