Documentation ¶
Overview ¶
Package config manages the environment variable configurations.
Index ¶
- Constants
- Variables
- func CheckDir(name, desc string) error
- func DownloadDir(logger *zap.SugaredLogger, srcDir, destDir, extraDir string) error
- func Format(name string) string
- func ImageDirs(logger *zap.SugaredLogger, c Config) error
- func IsHTML3(path string) bool
- func RemoveDir(name, path, root string) error
- func RemoveDownload(basename, path, destDir, extraDir string) error
- func RemoveImage(basename, path, destDir string) error
- func RenameDownload(basename, absPath string) error
- func StaticOriginal() string
- func StaticThumb() string
- func StringErr(err error) (int, string, error)
- func Validate(port uint) error
- type Config
- func (c Config) Addresses() (string, error)
- func (c Config) Archives(ctx context.Context, ce boil.ContextExecutor) error
- func (c Config) Assets(ctx context.Context, ce boil.ContextExecutor) error
- func (c *Config) Checks(logger *zap.SugaredLogger) error
- func (c Config) CustomErrorHandler(err error, ctx echo.Context)
- func (c Config) Envs() []string
- func (c Config) Helps() []string
- func (c Config) List() []Configuration
- func (c *Config) LogStore() error
- func (c Config) Names() []string
- func (c *Config) Override()
- func (c Config) RepairAssets(ctx context.Context, exec boil.ContextExecutor) error
- func (c *Config) SetupLogDir(logger *zap.SugaredLogger) error
- func (c Config) String() string
- func (c Config) UseHTTP() bool
- func (c Config) UseTLS() bool
- func (c Config) UseTLSLocal() bool
- func (c Config) Values() []string
- type Configuration
- type Repair
Constants ¶
const ( PortMax = 65534 // PortMax is the highest valid port number. PortSys = 1024 // PortSys is the lowest valid port number that does not require system access. DirWriteWriteBlock = 0o770 // Directory permissions. )
const ( ConfigDir = "defacto2-app" // ConfigDir is the subdirectory for the home user ".config". HTTPPort = 1323 // HTTPPort is the default port number for the unencrypted HTTP server. SessionHours = 3 // SessionHours is the default number of hours for the session cookie to remain active. MinimumFiles = 40000 // MinimumFiles is the minimum number of unique filenames expected in an asset subdirectory. )
Variables ¶
var ( ErrPortMax = fmt.Errorf("http port value must be between 1-%d", PortMax) ErrPortSys = fmt.Errorf("http port values between 1-%d require system access", PortSys) ErrDir = errors.New("the directory path is not set") ErrDir404 = errors.New("the directory path does not exist") ErrDirIs = errors.New("the directory path points to the file") ErrDirRead = errors.New("the directory path could not be read") ErrDirFew = errors.New("the directory path contains only a few items") ErrNoOAuth2 = errors.New("the production server requires a google, oauth2 client id to allow admin logins") ErrNoAccounts = errors.New("the production server has no google oauth2 user accounts to allow admin logins") ErrZap = errors.New("the zap logger instance is nil") )
var ( ErrDirNotExist = errors.New("directory does not exist or incorrectly typed") ErrEchoNil = errors.New("echo instance is nil") ErrLog = errors.New("the server cannot log to files") ErrNotDir = errors.New("directory path points to the file") ErrTouch = errors.New("the server cannot create a file in the directory") )
var ErrEmpty = errors.New("empty path or name")
var ErrNoPort = errors.New("the server cannot start without a http or a tls port")
Functions ¶
func CheckDir ¶
CheckDir runs checks against the named directory, including whether it exists, is a directory, and contains a minimum number of files. Problems will either log warnings or fatal errors.
func DownloadDir ¶ added in v0.8.2
func DownloadDir(logger *zap.SugaredLogger, srcDir, destDir, extraDir string) error
DownloadDir, on startup check the download directory for any invalid or unknown files.
func Format ¶ added in v0.8.0
Format returns a human readable description of the named configuration identifier.
func ImageDirs ¶ added in v0.8.2
func ImageDirs(logger *zap.SugaredLogger, c Config) error
ImageDirs, on startup check the image directories for any invalid or unknown files.
func RemoveDir ¶
RemoveDir, check the directory for invalid names. If any are found, they are printed to stderr. Any directory that matches the name ".stfolder" is removed.
func RemoveDownload ¶
RemoveDownload, check the download files for invalid names and extensions. If any are found, they are removed without warning. Basename must be the name of the file with a valid file extension.
Valid file extensions are none, .chiptune, .txt, and .zip.
func RemoveImage ¶
RemoveImage, check the image files for invalid names and extensions. If any are found, they are moved to the destDir without warning. Basename must be the name of the file with a valid file extension.
Valid file extensions are .png and .webp, and basename must be a valid uuid or cfid with the correct length.
func RenameDownload ¶
RenameDownload, rename the download file if the basename uses an invalid coldfusion uuid.
func StaticOriginal ¶
func StaticOriginal() string
StaticOriginal returns the path to the image directory.
func StaticThumb ¶
func StaticThumb() string
StaticThumb returns the path to the thumbnail directory.
Types ¶
type Config ¶
type Config struct { AbsLog string `env:"D2_DIR_LOG" help:"The absolute directory path will store all logs generated by this application"` AbsDownload string `env:"D2_DIR_DOWNLOAD" help:"The directory path that holds the UUID named files that are served as artifact downloads"` AbsPreview string `` /* 128-byte string literal not displayed */ AbsThumbnail string `` /* 133-byte string literal not displayed */ AbsExtra string `` /* 130-byte string literal not displayed */ AbsOrphaned string `env:"D2_DIR_ORPHANED" help:"The directory path that holds the UUID named files that are not linked to any database records"` DatabaseURL string `env:"D2_DATABASE_URL" help:"Provide the URL of the database to which to connect"` SessionKey string `` /* 128-byte string literal not displayed */ GoogleClientID string `env:"D2_GOOGLE_CLIENT_ID,unset" help:"The Google OAuth2 client ID"` GoogleIDs string `env:"D2_GOOGLE_IDS,unset" help:"Create a comma-separated list of Google account IDs to permit access to the editor mode"` MatchHost string `` /* 130-byte string literal not displayed */ TLSCert string `` /* 129-byte string literal not displayed */ TLSKey string `env:"D2_TLS_KEY" help:"An absolute file path to the TLS key, or leave blank to use a self-signed, localhost key"` HTTPPort uint `env:"D2_HTTP_PORT" help:"The port number to be used by the unencrypted HTTP web server"` MaxProcs uint `env:"D2_MAX_PROCS" help:"Limit the number of operating system threads the program can use"` SessionMaxAge int `` /* 146-byte string literal not displayed */ TLSPort uint `env:"D2_TLS_PORT" help:"The port number to be used by the encrypted, HTTPS web server"` Quiet bool `env:"D2_QUIET" help:"Suppress most startup output to the terminal, intended for use with systemd or other process managers"` Compression bool `` /* 129-byte string literal not displayed */ ProdMode bool `env:"D2_PROD_MODE" help:"Use the production mode to run checks on startup, log errors to files and recover from panics"` ReadOnly bool `` /* 126-byte string literal not displayed */ NoCrawl bool `env:"D2_NO_CRAWL" help:"Tell search engines to not crawl any of website pages or assets"` LogAll bool `env:"D2_LOG_ALL" help:"Log all HTTP and HTTPS client requests including those with 200 OK responses"` // GoogleAccounts is a slice of Google OAuth2 accounts that are allowed to login. // Each account is a 48 byte slice of bytes that represents the SHA-384 hash of the unique Google ID. GoogleAccounts [][48]byte }
Config options for the Defacto2 server using the caarlos0/env package.
caarlos0/env:https://github.com/caarlos0/env
func (Config) Archives ¶ added in v0.9.0
Archives, on startup check the download directory for any legacy and obsolete archives. Obsolete archives are those that use a legacy compression method that is not supported by Go or JS libraries used by the website.
func (Config) Assets ¶ added in v0.8.2
Assets, on startup check the file system directories for any invalid or unknown files. These specifically match the base filename against the UUID column in the database. When there is no matching UUID, the file is considered orphaned and these are moved to the orphaned directory without warning.
There are no checks on the 3 directories that get scanned.
func (*Config) Checks ¶
func (c *Config) Checks(logger *zap.SugaredLogger) error
Checks runs a number of sanity checks for the environment variable configurations.
func (Config) CustomErrorHandler ¶
CustomErrorHandler handles customer error templates.
func (Config) Envs ¶ added in v0.8.0
Envs returns a list of the environment variable names in the Config struct.
func (Config) List ¶ added in v0.8.0
func (c Config) List() []Configuration
List returns a list of the configuration options.
func (*Config) LogStore ¶
LogStore determines the local storage path for all log files created by this web application.
func (*Config) Override ¶
func (c *Config) Override()
Override the configuration settings fetched from the environment.
func (Config) RepairAssets ¶ added in v0.8.2
RepairAssets, on startup check the file system directories for any invalid or unknown files. If any are found, they are removed without warning.
func (*Config) SetupLogDir ¶
func (c *Config) SetupLogDir(logger *zap.SugaredLogger) error
SetupLogDir runs checks against the configured log directory. If no log directory is configured, a default directory is used. Problems will either log warnings or fatal errors.
func (Config) String ¶
String returns a string representation of the Config struct. The output is formatted as a table with the following columns: Environment variable and Value.
func (Config) UseTLSLocal ¶
UseTLSLocal returns true if the server is configured to use the local-mode.
type Configuration ¶ added in v0.8.0
type Configuration struct { Title string // Title is the name of the configuration option. Variable string // Variable is the environment variable name. Value string // Value of the configuration option that is safe to print. Description string // Description is the help text for the configuration option. }
Configuration is a struct that holds the configuration options.