252 lines
6.3 KiB
Go
252 lines
6.3 KiB
Go
package internal
|
|
|
|
import (
|
|
"net/url"
|
|
"time"
|
|
)
|
|
|
|
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 / pod operator
|
|
DefaultAdminUser = "admin"
|
|
DefaultAdminPass = "admiN"
|
|
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
|
|
|
|
// DefaultSessionCacheTTL is the server's default session cache ttl
|
|
DefaultSessionCacheTTL = 1 * time.Hour
|
|
|
|
// DefaultSessionExpiry is the server's default session expiry time
|
|
DefaultSessionExpiry = 240 * time.Hour // 10 days
|
|
|
|
// DefaultMagicLinkSecret is the jwt magic link secret
|
|
DefaultMagicLinkSecret = InvalidConfigValue
|
|
|
|
// Default SMTP configuration
|
|
DefaultSMTPHost = "smtp.gmail.com"
|
|
DefaultSMTPPort = 587
|
|
DefaultSMTPUser = InvalidConfigValue
|
|
DefaultSMTPPass = InvalidConfigValue
|
|
DefaultSMTPFrom = InvalidConfigValue
|
|
|
|
// DefaultAPISessionTime is the server's default session time for API tokens
|
|
DefaultAPISessionTime = 240 * time.Hour // 10 days
|
|
|
|
// DefaultAPISigningKey is the default API JWT signing key for tokens
|
|
DefaultAPISigningKey = InvalidConfigValue
|
|
)
|
|
|
|
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...`,
|
|
}
|
|
)
|
|
|
|
func NewConfig() *Config {
|
|
return &Config{
|
|
Debug: DefaultDebug,
|
|
|
|
Name: DefaultName,
|
|
Description: DefaultMetaDescription,
|
|
Store: DefaultStore,
|
|
Theme: DefaultTheme,
|
|
BaseURL: DefaultBaseURL,
|
|
|
|
CookieSecret: DefaultCookieSecret,
|
|
|
|
SearchPrompts: DefaultSearchPrompts,
|
|
ResultsPerPage: DefaultResultsPerPage,
|
|
|
|
SessionExpiry: DefaultSessionExpiry,
|
|
|
|
SMTPHost: DefaultSMTPHost,
|
|
SMTPPort: DefaultSMTPPort,
|
|
SMTPUser: DefaultSMTPUser,
|
|
SMTPPass: DefaultSMTPPass,
|
|
}
|
|
}
|
|
|
|
// Option is a function that takes a config struct and modifies it
|
|
type Option func(*Config) error
|
|
|
|
// WithDebug sets the debug mode lfag
|
|
func WithDebug(debug bool) Option {
|
|
return func(cfg *Config) error {
|
|
cfg.Debug = debug
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// WithData sets the data directory to use for storage
|
|
func WithData(data string) Option {
|
|
return func(cfg *Config) error {
|
|
cfg.Data = data
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// WithStore sets the store to use for accounts, sessions, etc.
|
|
func WithStore(store string) Option {
|
|
return func(cfg *Config) error {
|
|
cfg.Store = store
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// WithBaseURL sets the Base URL used for constructing feed URLs
|
|
func WithBaseURL(baseURL string) Option {
|
|
return func(cfg *Config) error {
|
|
u, err := url.Parse(baseURL)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
cfg.BaseURL = baseURL
|
|
cfg.baseURL = u
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// WithAdminName sets the Admin name used to identify the pod operator
|
|
func WithAdminName(adminName string) Option {
|
|
return func(cfg *Config) error {
|
|
cfg.AdminName = adminName
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// WithAdminEmail sets the Admin email used to contact the pod operator
|
|
func WithAdminEmail(adminEmail string) Option {
|
|
return func(cfg *Config) error {
|
|
cfg.AdminEmail = adminEmail
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// WithName sets the instance's name
|
|
func WithName(name string) Option {
|
|
return func(cfg *Config) error {
|
|
cfg.Name = name
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// WithDescription sets the instance's description
|
|
func WithDescription(description string) Option {
|
|
return func(cfg *Config) error {
|
|
cfg.Description = description
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// WithTheme sets the default theme to use
|
|
func WithTheme(theme string) Option {
|
|
return func(cfg *Config) error {
|
|
cfg.Theme = theme
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// WithCookieSecret sets the server's cookie secret
|
|
func WithCookieSecret(secret string) Option {
|
|
return func(cfg *Config) error {
|
|
cfg.CookieSecret = secret
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// WithResultsPerPage sets the server's results per page
|
|
func WithResultsPerPage(resultsPerPage int) Option {
|
|
return func(cfg *Config) error {
|
|
cfg.ResultsPerPage = resultsPerPage
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// WithSessionExpiry sets the server's session expiry time
|
|
func WithSessionExpiry(expiry time.Duration) Option {
|
|
return func(cfg *Config) error {
|
|
cfg.SessionExpiry = expiry
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// WithSMTPHost sets the SMTPHost to use for sending email
|
|
func WithSMTPHost(host string) Option {
|
|
return func(cfg *Config) error {
|
|
cfg.SMTPHost = host
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// WithSMTPPort sets the SMTPPort to use for sending email
|
|
func WithSMTPPort(port int) Option {
|
|
return func(cfg *Config) error {
|
|
cfg.SMTPPort = port
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// WithSMTPUser sets the SMTPUser to use for sending email
|
|
func WithSMTPUser(user string) Option {
|
|
return func(cfg *Config) error {
|
|
cfg.SMTPUser = user
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// WithSMTPPass sets the SMTPPass to use for sending email
|
|
func WithSMTPPass(pass string) Option {
|
|
return func(cfg *Config) error {
|
|
cfg.SMTPPass = pass
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// WithSMTPFrom sets the SMTPFrom address to use for sending email
|
|
func WithSMTPFrom(from string) Option {
|
|
return func(cfg *Config) error {
|
|
cfg.SMTPFrom = from
|
|
return nil
|
|
}
|
|
}
|