config

package
v2.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: MIT Imports: 16 Imported by: 0

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

View Source
const (
	DBJournalModeRollback = "DELETE"
	DBJournalModeWAL      = "WAL"

	WebFilesStoreOnDisk       = "on-disk"
	WebFilesStoreOnDiskMemory = "on-disk-memory"
	WebFilesStoreEmbedded     = "embedded"
)

Stuff used for validation.

View Source
const DefaultConfigFileName = "licensekeys.conf"

DefaultConfigFileName is the typical name of the config file.

Variables

View Source
var (
	//ErrNoFilePathGiven is returned when trying to parse the config file but no
	//file path was given.
	ErrNoFilePathGiven = errors.New("config: no file path given")
)

Errors.

Functions

func GetLocation

func GetLocation() *time.Location

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

func Read(path string, print bool) (err error)

Read handles reading and parsing the config file at the provided path. The parsed data is sanitized and validated.

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.

If the path is blank, a default in-app/in-memory config is used. If the path is provided but a file does not exist, a default config if written to the file at the path.

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.

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.
	UseLocalFiles bool   `yaml:"UseLocalFiles"` //Serve third-party CSS and JS files from this app's files or from an internet CDN.
	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.

	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.

func Data

func Data() File

Data returns the parsed config file data. This is used in other packages to use config file data.

Jump to

Keyboard shortcuts

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