config

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: GPL-3.0 Imports: 40 Imported by: 0

Documentation

Overview

Package config manages the environment variable configurations.

Index

Constants

View Source
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.
)
View Source
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.
	Down         = "AbsDownload"  // AbsDownload means the absolute download asset directory.
	Logger       = "AbsLog"       // AbsLog means the absolute log directory.
	Prev         = "AbsPreview"   // AbsPreview means the absolute preview assets directory.
	Thumb        = "AbsThumbnail" // AbsThumbnail means the absolute thumbnanil assets directory.
)

Variables

View Source
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")
)
View Source
var (
	ErrNoPort  = errors.New("the server cannot start without a http or a tls port")
	ErrPointer = errors.New("pointer is nil")
	ErrVer     = errors.New("postgresql version request failed")
)
View Source
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")
)
View Source
var (
	ErrCE    = errors.New("nil context executor")
	ErrEmpty = errors.New("empty path or name")
)

Functions

func CheckDir

func CheckDir(name, desc string) error

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

func Format(name string) string

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 IsHTML3

func IsHTML3(path string) bool

IsHTML3 returns true if the route is /html3.

func RecordCount added in v0.11.0

func RecordCount(ctx context.Context, db *sql.DB) int

RecordCount returns the number of records in the database.

func RemoveDir

func RemoveDir(name, path, root string) error

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

func RemoveDownload(basename, path, destDir, extraDir string) error

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

func RemoveImage(basename, path, backupDir string) error

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

func RenameDownload(basename, absPath string) error

RenameDownload, rename the download file if the basename uses an invalid coldfusion uuid.

func SanityTmpDir added in v0.11.0

func SanityTmpDir()

SanityTmpDir is used to print the temporary directory and its disk usage.

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.

func StringErr

func StringErr(err error) (int, string, error)

StringErr sends the error and code as a string.

func Validate

func Validate(port uint) error

Validate returns an error if the HTTP or TLS port is invalid.

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"`
	// 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
	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 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"`
}

Config options for the Defacto2 server using the caarlos0/env package.

caarlos0/env:https://github.com/caarlos0/env

func (Config) Addresses

func (c Config) Addresses() (string, error)

Addresses returns a list of urls that the server is accessible from.

func (Config) Archives added in v0.9.0

func (c Config) Archives(ctx context.Context, exec boil.ContextExecutor) error

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

func (c Config) Assets(ctx context.Context, exec boil.ContextExecutor) error

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

func (c Config) CustomErrorHandler(err error, ctx echo.Context)

CustomErrorHandler handles customer error templates.

func (Config) Envs added in v0.8.0

func (c Config) Envs() []string

Envs returns a list of the environment variable names in the Config struct.

func (Config) Fixer added in v0.11.0

func (c Config) Fixer() error

Fixer is used to fix any known issues with the file assets and the database entries.

func (Config) Helps added in v0.8.0

func (c Config) Helps() []string

Helps returns a list of the help text 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

func (c *Config) LogStore() error

LogStore determines the local storage path for all log files created by this web application.

func (Config) MagicNumbers added in v0.10.0

func (c Config) MagicNumbers(ctx context.Context, exec boil.ContextExecutor, logger *zap.SugaredLogger) error

MagicNumbers checks the magic numbers of the artifacts and replaces any missing or legacy values with the current method of detection. Previous detection methods were done using the `file` command line utility, which is a bit to verbose for our needs.

func (Config) Names added in v0.8.0

func (c Config) Names() []string

Names returns a list of the field names in the Config struct.

func (*Config) Override

func (c *Config) Override()

Override the configuration settings fetched from the environment.

func (Config) Previews added in v0.10.0

func (c Config) Previews(ctx context.Context, exec boil.ContextExecutor, logger *zap.SugaredLogger) error

Previews, on startup check the preview directory for any unnecessary preview images such as textfile artifacts.

func (Config) RepairAssets added in v0.8.2

func (c Config) RepairAssets(ctx context.Context, exec boil.ContextExecutor) error

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

func (c Config) String() 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) UseHTTP

func (c Config) UseHTTP() bool

UseHTTP returns true if the server is configured to use HTTP.

func (Config) UseTLS

func (c Config) UseTLS() bool

UseTLS returns true if the server is configured to use TLS.

func (Config) UseTLSLocal

func (c Config) UseTLSLocal() bool

UseTLSLocal returns true if the server is configured to use the local-mode.

func (Config) Values added in v0.8.0

func (c Config) Values() []string

Values returns a list of the values in the Config struct. These are not safe to print meaning that they may contain sensitive information.

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.

type Repair added in v0.9.0

type Repair int

Repair is a type of archive for the re-archive and recompress methods.

const (
	Zip Repair = iota // ZIP and PKZip archives
	LHA               // LHA and LZH archives
	Arc               // ARC archives
	Arj               // ARJ archives
)

func (Repair) String added in v0.9.0

func (r Repair) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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