Exemplo n.º 1
0
	"net"
	"net/http"
	"strings"

	"github.com/Sirupsen/logrus"
	"github.com/coreos/go-etcd/etcd"
	"github.com/namsral/flag"
)

var (
	configFlag       = flag.String("config", "", "Config file to read")                  // Enable config file cuntionality
	logFormatterType = flag.String("log_formatter_type", "text", "Log formatter to use") // Logrus log formatter
	logForceColors   = flag.Bool("log_force_colors", false, "Force colored log output?") // Logrus force colors
	etcdAddress      = flag.String("etcd_address", "", "Address of the etcd server to use")
	etcdPath         = flag.String("etcd_path", "", "Prefix of the etcd directory, no slash near the end")
	sessionCacheSize = flag.Int("session_cache_size", 64, "Size of the LRU client session cache")

	rawBind = flag.String("raw_bind", "0.0.0.0:80", "Address used for the HTTP server")
	tlsBind = flag.String("tls_bind", "0.0.0.0:443", "Address used for the HTTPS server")
)

var (
	tlsConfig *tls.Config
)

func main() {
	// Parse the flags
	flag.Parse()

	// Normalize the etcd path
	if (*etcdPath)[0] != '/' {
Exemplo n.º 2
0
func (a actionsMap) validAction(action string) bool {
	_, ok := a[action]
	return ok
}

func (a actionsMap) perform(action string) error {
	return a[action]()
}

var (
	dbUser = flag.String("db_user", "expensetracker", "database user to connect with")
	dbName = flag.String("db_name", "expensetracker", "name of the database to connect to")
	dbPw   = flag.String("db_pw", "", "user's database password")
	dbHost = flag.String("db_host", "localhost", "host the database is running on")
	dbPort = flag.Int("db_port", 5432, "port the database is listening on")

	port   = flag.Int("port", 8181, "HTTP port to listen on")
	action = flag.String("action", "start", "action to perform. Available: "+actions.available())

	adminName  = flag.String("admin_name", "", "Name of admin to add")
	adminEmail = flag.String("admin_email", "", "Email of admin to add")
	adminPw    = flag.String("admin_pw", "", "Password of admin to add")
)

func DBConn() (*sqlx.DB, error) {
	return sqlx.Open("postgres",
		fmt.Sprintf("user=%s dbname=%s password=%s host=%s port=%d sslmode=disable",
			*dbUser, *dbName, *dbPw, *dbHost, *dbPort))
}