Documentation
¶
Overview ¶
Package config manages the environment variable configurations.
Index ¶
- Constants
- Variables
- func CheckDir(name dir.Directory, desc string) error
- func DownloadDir(sl *slog.Logger, src, dest, extra dir.Directory) error
- func FileID(r io.Reader) bool
- func Format(name string) string
- func Googles(ids [][48]byte) string
- func Info(name string, value any) string
- func IsHTML3(path string) bool
- func RecordCount(ctx context.Context, db *sql.DB) int
- func Remove(diz, txt string) (string, error)
- func RemoveDir(sl *slog.Logger, name, path, root string) error
- func RemoveDownload(sl *slog.Logger, basename, path string, backup, extra dir.Directory) error
- func RemoveImage(sl *slog.Logger, basename, path string, backup dir.Directory) error
- func RenameDownload(sl *slog.Logger, basename, absPath string) error
- func StaticOriginal() string
- func StaticThumb() string
- func StringErr(err error) (int, string, error)
- func TmpCleaner(sl *slog.Logger)
- func TmpInfo(sl *slog.Logger)
- func Validate(port uint16) error
- type Absdown
- type Absextra
- type Abslog
- type Absorphan
- type Absprev
- type Absthumb
- type Abstlscrt
- type Abstlskey
- type Config
- func (c Config) Addresses(sl *slog.Logger) error
- func (c *Config) Archives(ctx context.Context, exec boil.ContextExecutor, sl *slog.Logger) error
- func (c *Config) Assets(ctx context.Context, exec boil.ContextExecutor, sl *slog.Logger) error
- func (c *Config) Checks(sl *slog.Logger) error
- func (c *Config) CustomErrorHandler(err error, ctx echo.Context, sl *slog.Logger)
- func (c *Config) Fixer(sl *slog.Logger, d time.Time) error
- func (c *Config) ImageDirs(sl *slog.Logger) error
- func (c *Config) LogStore() error
- func (c *Config) MagicNumbers(ctx context.Context, exec boil.ContextExecutor, sl *slog.Logger) error
- func (c Config) Names() []string
- func (c *Config) Override()
- func (c *Config) Previews(ctx context.Context, exec boil.ContextExecutor, sl *slog.Logger) error
- func (c Config) Print(sl *slog.Logger)
- func (c *Config) RepairAssets(ctx context.Context, exec boil.ContextExecutor, sl *slog.Logger) error
- func (c *Config) SetupLogDir(sl *slog.Logger) error
- func (c *Config) TextFiles(ctx context.Context, exec boil.ContextExecutor, sl *slog.Logger) error
- func (c Config) UseHTTP() bool
- func (c Config) UseTLS() bool
- func (c Config) UseTLSLocal() bool
- type Connection
- type Directory
- type File
- type Googleauth
- type Googleids
- type Hours
- type Matchhost
- type OAuth2s
- type Port
- type PortHTTP
- type PortTLS
- type Rearchiving
- type Repair
- type Sessionkey
- type Threads
- type Toggle
Constants ¶
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. )
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. )
const AbsPreview = "AbsPreview" // AbsPreview means the absolute preview assets directory.
const AbsThumbnail = "AbsThumbnail" // AbsThumbnail means the absolute thumbnail assets directory.
const DirWriteWriteBlock = 0o770 // Directory permissions.
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) )
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 ¶
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
DownloadDir on startup check the download directory for any invalid or unknown files.
func FileID ¶ added in v1.7.0
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
Format returns a human readable description of the named configuration identifier.
func Info ¶ added in v1.8.0
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 RecordCount ¶ added in v0.11.0
RecordCount returns the number of records in the database.
func Remove ¶ added in v1.7.0
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 ¶
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 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 ¶
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 ¶
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 TmpCleaner ¶ added in v1.7.3
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.
Types ¶
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) Archives ¶ added in v0.9.0
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
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 ¶
Checks runs a number of sanity checks for the environment variable configurations.
func (*Config) CustomErrorHandler ¶
CustomErrorHandler handles customer error templates.
func (*Config) Fixer ¶ added in v0.11.0
Fixer is used to fix any known issues with the file assets and the database entries.
func (*Config) ImageDirs ¶ added in v1.6.0
ImageDirs on startup check the image directories for any invalid or unknown files.
func (*Config) LogStore ¶
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) Override ¶
func (c *Config) Override()
Override the configuration settings fetched from the environment.
func (*Config) Previews ¶ added in v0.10.0
Previews on startup check the preview directory for any unnecessary preview images such as textfile artifacts.
func (Config) Print ¶ added in v1.8.0
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 ¶
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
TextFiles on startup check the extra directory for any readme text files that are duplicates of the diz text files.
func (Config) UseTLSLocal ¶
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.
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 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.
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.
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
Source Files
¶
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. |