Documentation
¶
Overview ¶
Package config manages the environment variable configurations.
Index ¶
- Constants
- Variables
- func CheckDir(name dir.Directory, desc string) error
- func Configured(name string, value any) string
- func CustomErrorHandler(sl *slog.Logger, c *echo.Context, err error)
- func DownloadDir(sl *slog.Logger, src, dest, extra dir.Directory) error
- func FileID(r io.Reader) bool
- func Help(o OAuth2s) string
- func RecordCount(ctx context.Context, exec boil.ContextExecutor) int64
- 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 TempInfo(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) Assets(ctx context.Context, sl *slog.Logger, exec boil.ContextExecutor) error
- func (c *Config) Checks(ctx context.Context, sl *slog.Logger) error
- func (c Config) Configurations(sl *slog.Logger)
- func (c *Config) Fixer(ctx context.Context, sl *slog.Logger, d time.Time) error
- func (c Config) Help() map[string]string
- func (c *Config) ImageDirs(sl *slog.Logger) error
- func (c *Config) LogStore() error
- func (c *Config) MagicNumbers(ctx context.Context, sl *slog.Logger, exec boil.ContextExecutor) error
- func (c Config) Names() []string
- func (c *Config) Override()
- func (c *Config) Previews(ctx context.Context, sl *slog.Logger, exec boil.ContextExecutor) error
- func (c Config) PurgeTemp() error
- func (c *Config) RepairArchives(ctx context.Context, sl *slog.Logger, exec boil.ContextExecutor) error
- func (c *Config) TextFiles(ctx context.Context, sl *slog.Logger, exec boil.ContextExecutor) error
- func (c Config) UseHTTP() bool
- func (c Config) UseLocal() bool
- func (c Config) UseTLS() bool
- func (c *Config) Warn(sl *slog.Logger, msg, name string, err error)
- type Connection
- type Directory
- type File
- type GoogleAuth
- type GoogleID
- type Helper
- type Hours
- type Issuer
- type Matchhost
- type OAuth2s
- type Port
- type PortHTTP
- type PortTLS
- type Repack
- type Repair
- type Sessionkey
- type Threads
- type Toggle
Constants ¶
const ( // ConfigDir is the subdirectory for the home user ".config". ConfigDir = "defacto2-app" // MinimumFiles is the minimum number of unique filenames expected in an asset subdirectory. MinimumFiles = 40_000 // SessionHours is the default number of hours for the session cookie to remain active. SessionHours = 3 // StdHTTP is the standard port used for a legacy unencrypted HTTP connection. StdHTTP Port = 80 // StdHTTPS is the standard port used for a HTTP web connection. StdHTTPS Port = 443 // StdCustom is the default port number used by this application for an unencrypted HTTP connection. StdCustom = 1323 )
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.
const (
Timeout = 1 * time.Minute
)
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("config: production server has no google oauth2 user accounts to allow admin logins") ErrNoOAuth2 = errors.New("config: production server requires a google, oauth2 client id to allow admin logins") ErrSession = errors.New("config: production server has user sessions that never expire") ErrNoDir = errors.New("config: directory does not exist on the host file system") ErrTouch = errors.New("config: directory does not permit file writing") ErrNotDir = errors.New("config: directory points to a file") ErrNotFile = errors.New("config: file path points to a directory") ErrNoPort = errors.New("config: no port, server cannot start without a configured http or a tls port") ErrNoPath = errors.New("config: no path, path or name cannot be empty") ErrFormat = errors.New("config: unsupported format") ErrPSVersion = errors.New("postgres did not return a version value") )
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 Configured ¶ added in v1.14.0
Configured returns both an about text and configured description for the named configuration.
The name is the configuration field such as "AbsLog" for D2_DIR_LOG. The value must be result of the configuration field.
func CustomErrorHandler ¶ added in v1.12.0
CustomErrorHandler handles edge case HTTP errors including issues such as missing template files, attempts at browsing restricted directories, etc.
The returned result will always be a text only HTTP response, as there is no ability to access HTML rendered pages.
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 RecordCount ¶ added in v0.11.0
func RecordCount(ctx context.Context, exec boil.ContextExecutor) int64
RecordCount returns the number of records in the database.
func Remove ¶ added in v1.7.0
Remove deletes either the named diz or txt file from an identical pair. The file deleted depends on whether the pair is identified as a FILE_ID.DIZ or a longer text file. If successful, the base name of the removed file 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.
Types ¶
type Config ¶
type Config struct {
AbsLog Abslog `env:"D2_DIR_LOG"` // absolute directory path to store log files
AbsDownload Absdown `env:"D2_DIR_DOWNLOAD"` // absolute directory path to the artifact file downloads
AbsPreview Absprev `env:"D2_DIR_PREVIEW"` // absolute directory path to the preview images
AbsThumbnail Absthumb `env:"D2_DIR_THUMBNAIL"` // absolute directory path to the thumbnail images
AbsExtra Absextra `env:"D2_DIR_EXTRA"` // absolute directory path to the artifact extras
AbsOrphaned Absorphan `env:"D2_DIR_ORPHANED"` // absolute directory path to the retired artifacts
DatabaseURL Connection `env:"D2_DATABASE_URL"` // url to the database
SessionKey Sessionkey `env:"D2_SESSION_KEY,unset"` // key or random value used for cookie encryption
SessionMaxAge Hours `env:"D2_SESSION_MAX_AGE"` // number of hours to keep a cookie session
GoogleClientID GoogleAuth `env:"D2_GOOGLE_CLIENT_ID,unset"` // google oauth2 clien id
GoogleIDs GoogleID `env:"D2_GOOGLE_IDS,unset"` // google accounts
HTTPPort PortHTTP `env:"D2_HTTP_PORT"` // port value for serving the website using http
TLSPort PortTLS `env:"D2_TLS_PORT"` // port value for serving the website using https
TLSCert Abstlscrt `env:"D2_TLS_CERT"` // absolute path to the tls certificate file
TLSKey Abstlskey `env:"D2_TLS_KEY"` // absolute path to the tls key file
MatchHost Matchhost `env:"D2_MATCH_HOST"` // restrict connections to specific internet hosts or ip addresses
MaxProcs Threads `env:"D2_MAX_PROCS"` // retrict the number of os threads the server can use
Quiet Toggle `env:"D2_QUIET"` // suppress startup terminal text
Compression Toggle `env:"D2_COMPRESSION"` // enable gzip compression when serving webpages
ProdMode Toggle `env:"D2_PROD_MODE"` // production mode, save log files and always recover from panics
ReadOnly Toggle `env:"D2_READ_ONLY"` // read only mode, disables all post, put, delete http requests
NoCrawl Toggle `env:"D2_NO_CRAWL"` // always insert a http header to ask search engines not to crawl the site
LogAll Toggle `env:"D2_LOG_ALL"` // log all client requests, both errors and successful responses
GoogleAccounts OAuth2s // GoogleAccounts is the data store for the GoogleIDs.
}
Config options for the Defacto2 server using the caarlos0/env package.
caarlos0/env:https://github.com/caarlos0/env
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) Configurations ¶ added in v1.14.0
Configurations prints the application settings to the logger.
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) Help ¶ added in v1.14.0
Help returns a mapped inventory of description texts for documentation/CLI usage.
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, sl *slog.Logger, exec boil.ContextExecutor) 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. MagicNumbers checks the magic numbers of the artifacts and replaces any missing or legacy values with the current method of detection.
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) RepairArchives ¶ added in v1.14.0
func (c *Config) RepairArchives(ctx context.Context, sl *slog.Logger, exec boil.ContextExecutor) error
RepairArchives 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) 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) UseLocal ¶ added in v1.12.0
UseLocal returns true if the server is configured to use the local TSL-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
func (Connection) String ¶ added in v1.14.0
func (c Connection) String() string
type Directory ¶ added in v1.8.0
type Directory string // Directory contains an absolute path to a directory.
type GoogleAuth ¶ added in v1.14.0
type GoogleAuth string
func (GoogleAuth) Help ¶ added in v1.14.0
func (g GoogleAuth) Help() string
func (GoogleAuth) LogValue ¶ added in v1.14.0
func (g GoogleAuth) LogValue() slog.Value
func (GoogleAuth) String ¶ added in v1.14.0
func (g GoogleAuth) String() string
type Helper ¶ added in v1.14.0
type Helper interface {
Help() string
}
Helper describes any config field capable of providing contextual guidance.
type Issuer ¶ added in v1.14.0
type Issuer interface {
Issue() string
}
Issuer describes any config field capable of reporting validation issues.
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 Repack ¶ added in v1.14.0
type Repack 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.
}
Repack 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.
func (Repair) NewArchive ¶ added in v1.14.0
NewArchive extracts the source archive file and then repackages (rearchives) it to a DEFLATE zip archive. The original source file is always kept.
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. |