config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2014 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

The module 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 CONFIG_NAME = "config.json"
View Source
const DEFAULT_CONFIG_NAME = "config.default.json"

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 ConfigCert `json:"ssl_certificate"`
	Auth           bool       `json:"basic_authenticate"`
	Authenticate   ConfigAuth `json:"authentication"`
	Libraries      []string   `json:"libraries"`
	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"`
}

The configuration type. Should contain representation for everything in config.json

func (*Config) CopyDefaultOverUser

func (cfg *Config) CopyDefaultOverUser() error

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

Returns the full path to the default configuration file

func (*Config) FindAndParse

func (cfg *Config) FindAndParse() error

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

func (*Config) UserConfigExists

func (cfg *Config) UserConfigExists() bool

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

func (*Config) UserConfigPath

func (cfg *Config) UserConfigPath() string

Returns the full path to the place where the user's configuration file should be

type ConfigAuth

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

type ConfigCert

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

type MergedConfig

type MergedConfig struct {
	Listen         *string     `json:"listen"`
	SSL            *bool       `json:"ssl"`
	SSLCertificate *ConfigCert `json:"ssl_certificate"`
	Auth           *bool       `json:"basic_authenticate"`
	Authenticate   *ConfigAuth `json:"authentication"`
	Libraries      *[]string   `json:"libraries"`
	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"`
}

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.

Jump to

Keyboard shortcuts

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