config

package
v0.0.0-...-6444359 Latest Latest
Warning

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

Go to latest
Published: May 29, 2014 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package config gives access to the dbm configuration file and the ability to create connection strings in order to connect with the configured databases.

Index

Constants

View Source
const (
	// CONFIG is the name of the configuration file.
	CONFIG = "config.toml"
	// DATA_DIR is the directory from ROOT where the database files live.
	DATA_DIR = "db"
)

Variables

View Source
var (
	// AllConfigs is all the environments.
	AllConfigs Configuration
	// Current is the config of the requested environment.
	Current *DB
)

Functions

func Load

func Load(env string) error

Load loads a configuration from CWD/db/config.toml first, if it cannot find that, it attempts to find the VCS root and do VCSROOT/db/config.toml.

func LoadFile

func LoadFile(path, env string) error

LoadFile loads a configuration at a particular path.

func Touch

func Touch(dir string) error

Touch creates a basic configuration file. Dir should be a path to where the config should be written.

Types

type Configuration

type Configuration map[string]*DB

Configuration is the type of the current config.

type DB

type DB struct {
	Name          string
	Kind          string
	Host          string
	User          string
	Pass          string
	SSL           bool
	SSLSkipVerify bool
}

DB is a database configuration.

func (*DB) DSN

func (d *DB) DSN() string

DSN creates a connection string from the database values given. Panics if DB doesn't have a kind of: "mysql", "postgres", or "sqlite3"

Different sql adapters will use different kinds of DSN strings. The strings generated here are useful with the following packages: MySQL: github.com/go-sql-driver/mysql Postgres: github.com/lib/pq Sqlite3: code.google.com/p/go-sqlite/go1/sqlite3

This will call DB.DSNSqlite3(useVcsRoot=true) if the kind is Sqlite3.

func (*DB) DSNSqlite3

func (d *DB) DSNSqlite3(useVcsRoot bool) string

DSNSqlite3 creates the filepath for a sqlite3 file. If the "name" from the config has the file path separator in it then no transformations will be done the path.

If there are no path separators then it will check the useVcsRoot value to determine which root directory to use (vcsRoot or cwd). In both cases the result will be ROOT/db/{name}.sqlite3

func (*DB) DSNnoDB

func (d *DB) DSNnoDB() string

DSNnoDB is exactly like DSN except it does not connect directly to the database instance, just to the server.

Jump to

Keyboard shortcuts

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