Documentation ¶
Overview ¶
Package config handles configuration of the app. The config data is used for low-level settings of the app and can be used elsewhere in this app.
The config file is in yaml format for easy readability. However, the file does not need to end in the yaml extension.
A config file can either be manually created, see template in _documenation, or it can be created upon first-run of this app if no config file exists at the given path. A default config will be used if no path to a config file is provided, although this should not really be used.
This package must not import any other packages from within this app to prevent import loops (besides minor utility packages).
---
When adding a new field to the config file:
- Add the field to the File type below.
- Determine any default value(s) for the field and set it in newDefaultConfig().
- Document the field in the template config file in the documenation.
- Set and validation in validate().
- Determine if the field should be listed in nonPublishedFields.
- Add the field to the diagnostics page, see pages.Diagnostics().
Try to keep the organization/order of the config fields the same between the config file templates, the type defined below, validation, and diagnostics.
Index ¶
Constants ¶
const ( DBJournalModeRollback = "DELETE" DBJournalModeWAL = "WAL" WebFilesStoreOnDisk = "on-disk" WebFilesStoreOnDiskMemory = "on-disk-memory" WebFilesStoreEmbedded = "embedded" )
Stuff used for validation.
const DefaultConfigFileName = "licensekeys.conf"
DefaultConfigFileName is the typical name of the config file.
Variables ¶
This section is empty.
Functions ¶
func GetLocation ¶
GetLocation returns the value of the tzLoc variable. This func is used so that the tzLoc variable isn't mistakenly overwritten if it were exported.
func Read ¶
Read handles reading and parsing the config file at the provided path. The parsed data is sanitized and validated. The print argument is used to print the config as it was read/parsed and as it was understood after sanitizing, validating, and handling default values.
The parsed configuration is stored in a local variable for access with the Data() func. This is done so that the config file doesn't need to be reparsed each time we want to get data from it.
Types ¶
type File ¶
type File struct { DBPath string `yaml:"DBPath"` //The path the the database file. DBJournalMode string `yaml:"DBJournalMode"` //Sets the mode for writing to the database file; delete or wal. WebFilesStore string `yaml:"WebFilesStore"` //Where HTML, CSS, and JS will be sourced and served from; on-disk, on-disk-memory, or embedded. WebFilesPath string `yaml:"WebFilesPath"` //The absolute path to the directory storing the app's HTML, CSS and JS files. FQDN string `yaml:"FQDN"` //The domain/subdomain the app serves on and matches your HTTPS certificate, also used for cookies. "." is acceptable but not advised. Port int `yaml:"Port"` //The port the app serves on. An HTTPS terminating proxy should redirect port 80 here. UseLocalFiles bool `yaml:"UseLocalFiles"` //Serve third-party CSS and JS files from this app's files or from an internet CDN. StaticFileCacheDays int `yaml:"StaticFileCacheDays"` //The number of days a browser will cache the app's CSS and JS files for. -1 disables caching. LoginLifetimeHours float64 `yaml:"LoginLifetimeHours"` //The time a user will remain logged in for. TwoFactorAuthLifetimeDays int `yaml:"TwoFactorAuthLifetimeDays"` //The time between when a 2FA token will be required. -1 requires it upon each login. Timezone string `yaml:"Timezone"` //Timezone in IANA format for displaying dates and times. MinPasswordLength int `yaml:"MinPasswordLength"` //The shortest length a new password can be. PrivateKeyEncryptionKey string `yaml:"PrivateKeyEncryptionKey"` //The key used to encrypt/decrypt the private keys stored in the db. This was if the db is compromised, the keys cannot be used. If not provided, private keys are stored in plaintext. Must be 16, 24, or 32 characters. //undocumented, not for end-user usage //Make sure each of these fields is in nonPublishedFields to prevent logging. Development bool `yaml:"Development"` //shows header in app that app is in development, uses non minified CSS & JSS, enabled some debugging, extra logging, etc. }
File defines the list of configuration fields. The value for each field will be set by a default or read from a config file. The config file is typically stored in the same directory as the executable.
Don't use uints! If user provided a negative number an ugly error message is kicked out. We would rather check for the negative number here and provide a nicer error message.