config

package
v1.8.5 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2025 License: GPL-3.0 Imports: 39 Imported by: 0

Documentation

Overview

Package config manages the environment variable configurations.

Index

Constants

View Source
const (
	ConfigDir         = "defacto2-app" // ConfigDir is the subdirectory for the home user ".config".
	MinimumFiles      = 40000          // MinimumFiles is the minimum number of unique filenames expected in an asset subdirectory.
	SessionHours      = 3              // SessionHours is the default number of hours for the session cookie to remain active.
	StdHTTP      Port = 80             // StdHTTP is the standard port used for a legacy unencrypted HTTP connection.
	StdHTTPS     Port = 443            // StdHTTPS is the standard port used for a HTTP web connection.
	StdCustom         = 1323           // StdCustom is the default port number used by this application for an unencrypted HTTP connection.
)
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.
)
View Source
const AbsPreview = "AbsPreview" // AbsPreview means the absolute preview assets directory.
View Source
const AbsThumbnail = "AbsThumbnail" // AbsThumbnail means the absolute thumbnail assets directory.
View Source
const DirWriteWriteBlock = 0o770 // Directory permissions.

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)
)
View Source
var (
	ErrNoAccounts = errors.New("the production server has no google oauth2 user accounts to allow admin logins")
	ErrNoDir      = errors.New("directory does not exist or incorrectly typed")
	ErrNoOAuth2   = errors.New("production server requires a google, oauth2 client id to allow admin logins")
	ErrNoPort     = errors.New("server cannot start withlogs.a http or a tls port")
	ErrNoPath     = errors.New("empty path or name")
	ErrPSVersion  = errors.New("postgres did not return a version value")
	ErrTouch      = errors.New("server cannot create a file in the directory")
	ErrNotDir     = errors.New("path points to a file")
	ErrNotFile    = errors.New("path points to a directory")
)

Functions

func CheckDir

func CheckDir(name dir.Directory, 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(sl *slog.Logger, src, dest, extra dir.Directory) error

DownloadDir on startup check the download directory for any invalid or unknown files.

func FileID added in v1.7.0

func FileID(r io.Reader) bool

FileID will return true if there are less than 10 lines of text and the maximum width of each line is no more than 45 characters. This is not a guarantee of a FILE_ID.DIZ but it is true for many situations.

func Format added in v0.8.0

func Format(name string) string

Format returns a human readable description of the named configuration identifier.

func Googles added in v1.8.0

func Googles(ids [][48]byte) string

Googles returns human readable help about the ids.

func Info added in v1.8.0

func Info(name string, value any) string

Info returns the results of the optional Info method for the named configuration identifier. The value needs to be the interface results of the field by name reflection.

func IsHTML3

func IsHTML3(path string) bool

IsHTML3 returns true if the rlogs. 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 Remove added in v1.7.0

func Remove(diz, txt string) (string, error)

Remove either the named diz or txt file that are idential duplicates. The file deleted depends on if the pair look to be a FILE_ID.DIZ or a longer form text file.

If successful, the basename of the file removed is returned.

func RemoveDir

func RemoveDir(sl *slog.Logger, 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(sl *slog.Logger, basename, path string, backup, extra dir.Directory) error

RemoveDownload checks 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(sl *slog.Logger, basename, path string, backup dir.Directory) error

RemoveImage checks 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(sl *slog.Logger, basename, absPath string) error

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.

func StringErr

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

StringErr sends the error and code as a string.

func TmpCleaner added in v1.7.3

func TmpCleaner(sl *slog.Logger)

TmpCleaner will remove any temporary directories created by this web applcation that are older than 3 days.

This is a safety measure to ensure that the server does not run out of disk space.

func TmpInfo added in v1.8.0

func TmpInfo(sl *slog.Logger)

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

func Validate

func Validate(port uint16) error

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

Types

type Absdown added in v1.8.0

type Absdown Directory

func (Absdown) Help added in v1.8.0

func (a Absdown) Help() string

func (Absdown) Issue added in v1.8.0

func (a Absdown) Issue() string

func (Absdown) LogValue added in v1.8.0

func (a Absdown) LogValue() slog.Value

func (Absdown) String added in v1.8.0

func (a Absdown) String() string

type Absextra added in v1.8.0

type Absextra Directory

func (Absextra) Help added in v1.8.0

func (a Absextra) Help() string

func (Absextra) Issue added in v1.8.0

func (a Absextra) Issue() string

func (Absextra) LogValue added in v1.8.0

func (a Absextra) LogValue() slog.Value

func (Absextra) String added in v1.8.0

func (a Absextra) String() string

type Abslog added in v1.8.0

type Abslog Directory

func (Abslog) Help added in v1.8.0

func (a Abslog) Help() string

func (Abslog) Issue added in v1.8.0

func (a Abslog) Issue() string

func (Abslog) LogValue added in v1.8.0

func (a Abslog) LogValue() slog.Value

func (Abslog) String added in v1.8.0

func (a Abslog) String() string

type Absorphan added in v1.8.0

type Absorphan Directory

func (Absorphan) Help added in v1.8.0

func (a Absorphan) Help() string

func (Absorphan) Issue added in v1.8.0

func (a Absorphan) Issue() string

func (Absorphan) LogValue added in v1.8.0

func (a Absorphan) LogValue() slog.Value

func (Absorphan) String added in v1.8.0

func (a Absorphan) String() string

type Absprev added in v1.8.0

type Absprev Directory

func (Absprev) Help added in v1.8.0

func (a Absprev) Help() string

func (Absprev) Issue added in v1.8.0

func (a Absprev) Issue() string

func (Absprev) LogValue added in v1.8.0

func (a Absprev) LogValue() slog.Value

func (Absprev) String added in v1.8.0

func (a Absprev) String() string

type Absthumb added in v1.8.0

type Absthumb Directory

func (Absthumb) Help added in v1.8.0

func (a Absthumb) Help() string

func (Absthumb) Issue added in v1.8.0

func (a Absthumb) Issue() string

func (Absthumb) LogValue added in v1.8.0

func (a Absthumb) LogValue() slog.Value

func (Absthumb) String added in v1.8.0

func (a Absthumb) String() string

type Abstlscrt added in v1.8.0

type Abstlscrt File

func (Abstlscrt) Help added in v1.8.0

func (a Abstlscrt) Help() string

func (Abstlscrt) Issue added in v1.8.0

func (a Abstlscrt) Issue() string

func (Abstlscrt) LogValue added in v1.8.0

func (a Abstlscrt) LogValue() slog.Value

func (Abstlscrt) String added in v1.8.0

func (a Abstlscrt) String() string

type Abstlskey added in v1.8.0

type Abstlskey File

func (Abstlskey) Help added in v1.8.0

func (a Abstlskey) Help() string

func (Abstlskey) Issue added in v1.8.0

func (a Abstlskey) Issue() string

func (Abstlskey) LogValue added in v1.8.0

func (a Abstlskey) LogValue() slog.Value

func (Abstlskey) String added in v1.8.0

func (a Abstlskey) String() string

type Config

type Config struct {
	AbsLog         Abslog     `env:"D2_DIR_LOG" help:"The absolute directory path will store all logs generated by this application"`
	AbsDownload    Absdown    `env:"D2_DIR_DOWNLOAD" help:"The directory path that holds the UUID named files that are served as artifact downloads"`
	AbsPreview     Absprev    `` /* 128-byte string literal not displayed */
	AbsThumbnail   Absthumb   `` /* 133-byte string literal not displayed */
	AbsExtra       Absextra   `` /* 130-byte string literal not displayed */
	AbsOrphaned    Absorphan  `env:"D2_DIR_ORPHANED" help:"The directory path that holds the UUID named files that are not linked to any database records"`
	DatabaseURL    Connection `env:"D2_DATABASE_URL" help:"Provide the URL of the database to which to connect"`
	SessionKey     Sessionkey `` /* 128-byte string literal not displayed */
	GoogleClientID Googleauth `env:"D2_GOOGLE_CLIENT_ID,unset" help:"The Google OAuth2 client ID"`
	GoogleIDs      Googleids  `env:"D2_GOOGLE_IDS,unset" help:"Create a comma-separated list of Google account IDs to permit access to the editor mode"`
	MatchHost      Matchhost  `` /* 130-byte string literal not displayed */
	TLSCert        Abstlscrt  `` /* 129-byte string literal not displayed */
	TLSKey         Abstlskey  `env:"D2_TLS_KEY" help:"An absolute file path to the TLS key, or leave blank to use a self-signed, localhost key"`
	GoogleAccounts OAuth2s    // GoogleAccounts is the data store for the GoogleIDs.
	HTTPPort       PortHTTP   `env:"D2_HTTP_PORT" help:"The port number to be used by the unencrypted HTTP web server"`
	MaxProcs       Threads    `env:"D2_MAX_PROCS" help:"Limit the number of operating system threads the program can use"`
	SessionMaxAge  Hours      `` /* 146-byte string literal not displayed */
	TLSPort        PortTLS    `env:"D2_TLS_PORT" help:"The port number to be used by the encrypted, HTTPS web server"`
	Quiet          Toggle     `env:"D2_QUIET" help:"Suppress most startup output to the terminal, intended for use with systemd or other process managers"`
	Compression    Toggle     `` /* 129-byte string literal not displayed */
	ProdMode       Toggle     `env:"D2_PROD_MODE" help:"Use the production mode to log errors to files and recover from panics"`
	ReadOnly       Toggle     `` /* 126-byte string literal not displayed */
	NoCrawl        Toggle     `env:"D2_NO_CRAWL" help:"Tell search engines to not crawl any of website pages or assets"`
	LogAll         Toggle     `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(sl *slog.Logger) 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, sl *slog.Logger,
) error

Archives checks 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, sl *slog.Logger) error

Assets on startup checks 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(sl *slog.Logger) 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, sl *slog.Logger)

CustomErrorHandler handles customer error templates.

func (*Config) Fixer added in v0.11.0

func (c *Config) Fixer(sl *slog.Logger, d time.Time) error

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

func (*Config) ImageDirs added in v1.6.0

func (c *Config) ImageDirs(sl *slog.Logger) error

ImageDirs on startup check the image directories for any invalid or unknown files.

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, sl *slog.Logger) 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, sl *slog.Logger) error

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

func (Config) Print added in v1.8.0

func (c Config) Print(sl *slog.Logger)

Print the configuration using the sl logger. Configurations names are obtained from the Config struct and are parsed with custom help and issue reports.

func (*Config) RepairAssets added in v0.8.2

func (c *Config) RepairAssets(ctx context.Context, exec boil.ContextExecutor, sl *slog.Logger) 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(sl *slog.Logger) 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) TextFiles added in v1.5.18

func (c *Config) TextFiles(ctx context.Context, exec boil.ContextExecutor, sl *slog.Logger) error

TextFiles on startup check the extra directory for any readme text files that are duplicates of the diz text files.

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.

type Connection added in v1.8.0

type Connection string

func (Connection) LogValue added in v1.8.0

func (c Connection) LogValue() slog.Value

type Directory added in v1.8.0

type Directory string // Directory contains an absolute path to a directory.

func (Directory) Check added in v1.8.0

func (d Directory) Check() error

func (Directory) Issue added in v1.8.0

func (d Directory) Issue() string

func (Directory) LogValue added in v1.8.0

func (d Directory) LogValue() slog.Value

func (Directory) String added in v1.8.0

func (d Directory) String() string

type File added in v1.8.0

type File string // File contains an absolute path to a file.

func (File) Check added in v1.8.0

func (f File) Check() error

func (File) Issue added in v1.8.0

func (f File) Issue() string

func (File) LogValue added in v1.8.0

func (f File) LogValue() slog.Value

func (File) String added in v1.8.0

func (f File) String() string

type Googleauth added in v1.8.0

type Googleauth string

func (Googleauth) Help added in v1.8.0

func (g Googleauth) Help() string

func (Googleauth) LogValue added in v1.8.0

func (g Googleauth) LogValue() slog.Value

func (Googleauth) String added in v1.8.0

func (g Googleauth) String() string

type Googleids added in v1.8.0

type Googleids string

func (Googleids) Help added in v1.8.0

func (g Googleids) Help() string

func (Googleids) LogValue added in v1.8.0

func (g Googleids) LogValue() slog.Value

func (Googleids) String added in v1.8.0

func (g Googleids) String() string

type Hours added in v1.8.0

type Hours int // Hours is a duration value

func (Hours) Int added in v1.8.0

func (h Hours) Int() int

func (Hours) LogValue added in v1.8.0

func (h Hours) LogValue() slog.Value

func (Hours) String added in v1.8.0

func (h Hours) String() string

type Matchhost added in v1.8.0

type Matchhost string

func (Matchhost) Help added in v1.8.0

func (m Matchhost) Help() string

func (Matchhost) LogValue added in v1.8.0

func (m Matchhost) LogValue() slog.Value

func (Matchhost) String added in v1.8.0

func (m Matchhost) String() string

type OAuth2s added in v1.8.0

type OAuth2s [][48]byte

OAuth2s 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.

func (OAuth2s) Help added in v1.8.0

func (o OAuth2s) Help() string

func (OAuth2s) LogValue added in v1.8.0

func (o OAuth2s) LogValue() slog.Value

func (OAuth2s) String added in v1.8.0

func (o OAuth2s) String() string

func (OAuth2s) Values added in v1.8.0

func (o OAuth2s) Values() [][48]byte

type Port added in v1.8.0

type Port uint16 // Port is a network port number.

func (Port) Check added in v1.8.0

func (p Port) Check() error

func (Port) LogValue added in v1.8.0

func (p Port) LogValue() slog.Value

func (Port) Value added in v1.8.0

func (p Port) Value() uint16

type PortHTTP added in v1.8.0

type PortHTTP Port

func (PortHTTP) Check added in v1.8.0

func (p PortHTTP) Check() error

func (PortHTTP) Help added in v1.8.0

func (p PortHTTP) Help() string

func (PortHTTP) LogValue added in v1.8.0

func (p PortHTTP) LogValue() slog.Value

func (PortHTTP) Value added in v1.8.0

func (p PortHTTP) Value() uint16

type PortTLS added in v1.8.0

type PortTLS Port

func (PortTLS) Check added in v1.8.0

func (p PortTLS) Check() error

func (PortTLS) Help added in v1.8.0

func (p PortTLS) Help() string

func (PortTLS) LogValue added in v1.8.0

func (p PortTLS) LogValue() slog.Value

func (PortTLS) Value added in v1.8.0

func (p PortTLS) Value() uint16

type Rearchiving added in v1.8.0

type Rearchiving struct {
	Source      string        // Source is the file extracted to a temporary directory and re-compressed.
	UID         string        // UID is the destination filename using a universal unique ID naming syntax.
	Destination dir.Directory // Destination is the directory to save the re-compressed file.
}

Rearchiving are the source and destination arguments required by the ReArchive Repair method.

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) ReArchive added in v1.0.6

func (r Repair) ReArchive(ctx context.Context, sl *slog.Logger, ra Rearchiving) error

ReArchive the file using the specified compression method. The original ra.Source file is not removed.

func (Repair) String added in v0.9.0

func (r Repair) String() string

type Sessionkey added in v1.8.0

type Sessionkey string

func (Sessionkey) Help added in v1.8.0

func (s Sessionkey) Help() string

func (Sessionkey) LogValue added in v1.8.0

func (s Sessionkey) LogValue() slog.Value

func (Sessionkey) String added in v1.8.0

func (s Sessionkey) String() string

type Threads added in v1.8.0

type Threads uint

func (Threads) Help added in v1.8.0

func (t Threads) Help() string

func (Threads) LogValue added in v1.8.0

func (t Threads) LogValue() slog.Value

func (Threads) String added in v1.8.0

func (t Threads) String() string

type Toggle added in v1.8.0

type Toggle bool // Toggle is a boolean value that returns a humanized string.

func (Toggle) Bool added in v1.8.0

func (t Toggle) Bool() bool

func (Toggle) LogValue added in v1.8.0

func (t Toggle) LogValue() slog.Value

Directories

Path Synopsis
Package fixarc checks for redundant SAE ARC files that require re-archiving.
Package fixarc checks for redundant SAE ARC files that require re-archiving.
Package fixarj checks for legacy ARJ files that require re-archiving.
Package fixarj checks for legacy ARJ files that require re-archiving.
Package fixlha checks for legacy LHA files that require re-archiving.
Package fixlha checks for legacy LHA files that require re-archiving.
Package fixzip checks for legacy ZIP files with out-of-date compression that require re-archiving.
Package fixzip checks for legacy ZIP files with out-of-date compression that require re-archiving.

Jump to

Keyboard shortcuts

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