config

package
v0.0.0-...-0bc05a2 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2016 License: MIT Imports: 10 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = Config{
	Cookie:    DefaultCookie,
	Port:      8080,
	StaticURL: "/static/",
	Metadata:  Metadata{},
}

Default is a basic configuration with insecure values. It will return the Address localhost:8080

View Source
var DefaultCookie = CookieConfig{
	Age:      14 * 24 * time.Hour,
	Domain:   "",
	HttpOnly: false,
	Name:     "sessionid",
	Path:     "/",
	Secure:   false,
}

DefaultCookie is a default CookieConfig implementation. It expires after two weeks and is not very secure.

Functions

func ParseGooseYAML

func ParseGooseYAML(path string) (conf map[string]DatabaseConfig, err error)

ParseGooseYAML will parse the entire goose database configuration file.

Types

type Config

type Config struct {
	HTTPS       bool           `json:"https"`
	Domain      string         `json:"domain"`
	ProxyDomain string         `json:"proxy_domain"`
	Port        int            `json:"port"`
	ProxyPort   int            `json:"proxy_port"`
	TemplateDir string         `json:"templates"`
	AbsPath     string         `json:"abs_path"`
	MediaDir    string         `json:"media"`
	MediaURL    string         `json:"media_url"`
	StaticDir   string         `json:"static"`
	StaticURL   string         `json:"static_url"`
	SecretKey   string         `json:"secret_key"`
	Database    DatabaseConfig `json:"database"`
	Cookie      CookieConfig   `json:"cookie"`
	SMTP        SMTPConfig     `json:"smtp"`
	Metadata    Metadata       `json:"metadata"`
}

Config is the parent configuration struct and includes fields for single configurations of a database, cookie, and SMTP connection.

func DefaultConfig

func DefaultConfig(key string) Config

DefaultConfig will return a basic configuration with insecure values. It allows the specification of a secret key.

func Parse

func Parse() (Config, error)

Parse will create a Config using the file settings.json in the current directory.

func ParseFile

func ParseFile(filename string) (Config, error)

ParseFile will create a Config using the file at the given path.

func (Config) Address

func (c Config) Address() string

Address returns the domain:port pair.

func (Config) FullAddress

func (c Config) FullAddress() string

FullAddress returns the scheme, domain, port, and host

func (Config) URL

func (c Config) URL() (u *url.URL)

URL returns the domain:port scheme. Port is omitted if 80.

type CookieConfig

type CookieConfig struct {
	Age      time.Duration `json:"age"`
	Domain   string        `json:"domain"`
	HttpOnly bool          `json:"http_only"`
	Name     string        `json:"name"`
	Path     string        `json:"path"`
	Secure   bool          `json:"secure"`
}

CookieConfig contains the fields needed to set and retrieve cookies. Cookie names are valid tokens as defined by RFC 2616 section 2.2: http://tools.ietf.org/html/rfc2616#section-2.2 TL;DR: Any non-control or non-separator character.

type DatabaseConfig

type DatabaseConfig struct {
	Driver   string `json:"driver"`
	Host     string `json:"host"`
	Port     int64  `json:"port"`
	Name     string `json:"name"`
	User     string `json:"user"`
	Password string `json:"password"`
	SSLMode  string `json:"ssl_mode"`
}

DatabaseConfig contains the fields needed to connect to a database.

func ParseDatabaseFile

func ParseDatabaseFile(filepath string) (c DatabaseConfig, err error)

ParseDatabaseFile will create a DatabaseConfig using the given filepath.

func ParseGooseDatabase

func ParseGooseDatabase(path, name string) (c DatabaseConfig, err error)

ParseGooseDatabase will parse a specific database name in the goose configuration file.

func (DatabaseConfig) Credentials

func (db DatabaseConfig) Credentials() string

Credentials with return a string of credentials appropriate for Go's sql.Open function

type GooseConfig

type GooseConfig map[string]struct {
	Driver string
	Open   string
}

GooseConfig is a representation of database configurations for the goose migration tool: https://bitbucket.org/liamstask/goose

type Metadata

type Metadata map[string]string

Metadata holds arbitrary strings as key - value pairs

func (Metadata) Get

func (m Metadata) Get(key string) string

Get returns the value of the given key. If the key does not exist in the metadata, a blank string will be returned

func (Metadata) Has

func (m Metadata) Has(key string) (exists bool)

Has returns true if the metadata contains the key. Keys with blank values will return true.

func (Metadata) Keys

func (m Metadata) Keys() []string

Keys returns all keys of the metadata

func (Metadata) Values

func (m Metadata) Values() []string

Values returns all values of the metadata

type SMTPConfig

type SMTPConfig struct {
	Port     int64  `json:"port"`
	User     string `json:"user"`
	Password string `json:"password"`
	Host     string `json:"host"`
	From     string `json:"from"`
	Alias    string `json:"alias"`
}

SMTPConfig contains the fields needed to connect to a SMTP server.

func (SMTPConfig) Address

func (c SMTPConfig) Address() string

Address will return a string of the host and port separated by a colon.

func (SMTPConfig) FromAddress

func (c SMTPConfig) FromAddress() string

FromAddress creates a string suitable for use in an Email's From header.

Jump to

Keyboard shortcuts

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