config

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2016 License: GPL-3.0 Imports: 10 Imported by: 0

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

View Source
const ConfigName = "config.json"

ConfigName contains the name of the actual configuration file. This is the one the user is supposed to change.

View Source
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 Auth added in v1.0.2

type Auth struct {
	User     string `json:"user"`
	Password string `json:"password"`
}

Auth represents a configuration HTTP Basic authentication

type Cert added in v1.0.2

type Cert struct {
	Crt string `json:"crt"`
	Key string `json:"key"`
}

Cert represents a configuration for TLS certificate

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

func (cfg *Config) CopyDefaultOverUser() error

CopyDefaultOverUser will create (or replace if neccessery) the user configuration using the default config file supplied with the installation.

func (*Config) DefaultConfigPath

func (cfg *Config) DefaultConfigPath() string

DefaultConfigPath returns the full path to the default configuration file

func (*Config) FindAndParse

func (cfg *Config) FindAndParse() error

FindAndParse actually finds the configuration file, parsing it and merging it on top the default configuration.

func (*Config) UserConfigExists

func (cfg *Config) UserConfigExists() bool

UserConfigExists returns true if the user configuration is present and in order. Otherwise false.

func (*Config) UserConfigPath

func (cfg *Config) UserConfigPath() string

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.

Jump to

Keyboard shortcuts

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