Documentation
¶
Overview ¶
Package config is resposible for finding, parsing and merging the HTTPMS user configuration with the default. Configuration locations should be different depending on the host OS.
Linux/BSD configurations should be in $HOME/.httpms/config.json Windows configurations should be in %APPDATA%/httpms/config.json
Index ¶
Constants ¶
const ConfigName = "config.json"
ConfigName contains the name of the actual configuration file. This is the one the user is supposed to change.
const DefaultConfigName = "config.default.json"
DefaultConfigName contains the name of the file which contains the default configuration values for HTTPMS. It shouldn't be edited by a user and it is part of the app installation. Preferably, it should be hidden away.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Listen string `json:"listen"`
SSL bool `json:"ssl"`
SSLCertificate Cert `json:"ssl_certificate"`
Auth bool `json:"basic_authenticate"`
Authenticate Auth `json:"authentication"`
Libraries []string `json:"libraries"`
LibraryScan ScanSection `json:"library_scan"`
UserPath string `json:"user_path"`
LogFile string `json:"log_file"`
SqliteDatabase string `json:"sqlite_database"`
Gzip bool `json:"gzip"`
ReadTimeout int `json:"read_timeout"`
WriteTimeout int `json:"write_timeout"`
MaxHeadersSize int `json:"max_header_bytes"`
HTTPRoot string `json:"http_root"`
}
Config contains representation for everything in config.json
func (*Config) CopyDefaultOverUser ¶
CopyDefaultOverUser will create (or replace if neccessery) the user configuration using the default config file supplied with the installation.
func (*Config) DefaultConfigPath ¶
DefaultConfigPath returns the full path to the default configuration file
func (*Config) FindAndParse ¶
FindAndParse actually finds the configuration file, parsing it and merging it on top the default configuration.
func (*Config) UserConfigExists ¶
UserConfigExists returns true if the user configuration is present and in order. Otherwise false.
func (*Config) UserConfigPath ¶
UserConfigPath returns the full path to the place where the user's configuration file should be
type MergedConfig ¶
type MergedConfig struct {
Listen *string `json:"listen"`
SSL *bool `json:"ssl"`
SSLCertificate *Cert `json:"ssl_certificate"`
Auth *bool `json:"basic_authenticate"`
Authenticate *Auth `json:"authentication"`
Libraries *[]string `json:"libraries"`
LibraryScan *ScanSection `json:"library_scan"`
UserPath *string `json:"user_path"`
LogFile *string `json:"log_file"`
SqliteDatabase *string `json:"sqlite_database"`
Gzip *bool `json:"gzip"`
ReadTimeout *int `json:"read_timeout"`
WriteTimeout *int `json:"write_timeout"`
MaxHeadersSize *int `json:"max_header_bytes"`
HTTPRoot *string `json:"http_root"`
}
MergedConfig is used for merging one config over the other. I need the zero value for every Field to be nil so that I can destinguish if it has been in the json file or not. If I did not use pointers I would not have been able to do that. That way the merged (user) json can contain a subset of all fields and everything else will be used from the default json. Unfortunatelly this leads to repetition since MergedConfig must have the same fields in the same order as Config.
type ScanSection ¶ added in v1.0.2
type ScanSection struct {
FilesPerOperation int64 `json:"files_per_operation"`
SleepPerOperation time.Duration `json:"sleep_after_operation"`
InitialWait time.Duration `json:"initial_wait_duration"`
}
ScanSection is used for merging the two configs. Its purpose is to essentially hold the default values for its properties.
func (*ScanSection) UnmarshalJSON ¶ added in v1.0.2
func (ss *ScanSection) UnmarshalJSON(input []byte) error
UnmarshalJSON parses a JSON and populets its ScanSection. Satisfies the Unmrashaller interface.