From 27cf35d185696f742446fb35226833b1adf94a94 Mon Sep 17 00:00:00 2001 From: Ian Kent Date: Wed, 29 Oct 2014 16:59:59 +0000 Subject: [PATCH] Configure from environment --- Makefile | 1 + README.md | 20 ++++++++++---------- bindata.go | 8 ++++---- main.go | 20 +++++++++++--------- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 53927e9..0b5379c 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ fmt: deps: go get github.com/ian-kent/gotcha/... go get github.com/ian-kent/go-log/log + go get github.com/ian-kent/envconf go get github.com/jteeuwen/go-bindata/... go get labix.org/v2/mgo diff --git a/README.md b/README.md index f382663..e0b4761 100644 --- a/README.md +++ b/README.md @@ -39,17 +39,17 @@ on port 8025, and in-memory message storage will be used. ### Configuration -You can configure Go-MailHog using command line options: +You can configure Go-MailHog using command line options or environment variables: -| Parameter | Default | Description -| ------------- | --------------- | ----------- -| -hostname | mailhog.example | Hostname to use for EHLO/HELO and message IDs -| -httpbindaddr | 0.0.0.0:8025 | Interface and port for HTTP server to bind to -| -mongocoll | messages | MongoDB collection name for message storage -| -mongodb | mailhog | MongoDB database name for message storage -| -mongouri | 127.0.0.1:27017 | MongoDB host and port -| -smtpbindaddr | 0.0.0.0:1025 | Interface and port for SMTP server to bind to -| -storage | memory | Set message storage: memory / mongodb +| Environment | Command line | Default | Description +| ------------------- | ------------- | --------------- | ----------- +| MH_HOSTNAME | -hostname | mailhog.example | Hostname to use for EHLO/HELO and message IDs +| MH_HTTP_BIND_ADDR | -httpbindaddr | 0.0.0.0:8025 | Interface and port for HTTP server to bind to +| MH_MONGO_COLLECTION | -mongocoll | messages | MongoDB collection name for message storage +| MH_MONGO_DB | -mongodb | mailhog | MongoDB database name for message storage +| MH_MONGO_URI | -mongouri | 127.0.0.1:27017 | MongoDB host and port +| MH_SMTP_BIND_ADDR | -smtpbindaddr | 0.0.0.0:1025 | Interface and port for SMTP server to bind to +| MH_STORAGE | -storage | memory | Set message storage: memory / mongodb ### Contributing diff --git a/bindata.go b/bindata.go index 357ebe3..6a13ecd 100644 --- a/bindata.go +++ b/bindata.go @@ -1038,10 +1038,6 @@ type _bintree_t struct { var _bintree = &_bintree_t{nil, map[string]*_bintree_t{ "assets": &_bintree_t{nil, map[string]*_bintree_t{ - "templates": &_bintree_t{nil, map[string]*_bintree_t{ - "index.html": &_bintree_t{assets_templates_index_html, map[string]*_bintree_t{}}, - "layout.html": &_bintree_t{assets_templates_layout_html, map[string]*_bintree_t{}}, - }}, "images": &_bintree_t{nil, map[string]*_bintree_t{ "ajax-loader.gif": &_bintree_t{assets_images_ajax_loader_gif, map[string]*_bintree_t{}}, "github.png": &_bintree_t{assets_images_github_png, map[string]*_bintree_t{}}, @@ -1050,5 +1046,9 @@ var _bintree = &_bintree_t{nil, map[string]*_bintree_t{ "js": &_bintree_t{nil, map[string]*_bintree_t{ "controllers.js": &_bintree_t{assets_js_controllers_js, map[string]*_bintree_t{}}, }}, + "templates": &_bintree_t{nil, map[string]*_bintree_t{ + "index.html": &_bintree_t{assets_templates_index_html, map[string]*_bintree_t{}}, + "layout.html": &_bintree_t{assets_templates_layout_html, map[string]*_bintree_t{}}, + }}, }}, }} diff --git a/main.go b/main.go index aafaf00..4e8cc86 100644 --- a/main.go +++ b/main.go @@ -2,17 +2,19 @@ package main import ( "flag" + "net" + "os" + "github.com/ian-kent/Go-MailHog/mailhog/config" mhhttp "github.com/ian-kent/Go-MailHog/mailhog/http" "github.com/ian-kent/Go-MailHog/mailhog/http/api" "github.com/ian-kent/Go-MailHog/mailhog/smtp" "github.com/ian-kent/Go-MailHog/mailhog/storage" + "github.com/ian-kent/envconf" "github.com/ian-kent/go-log/log" gotcha "github.com/ian-kent/gotcha/app" "github.com/ian-kent/gotcha/events" "github.com/ian-kent/gotcha/http" - "net" - "os" ) var conf *config.Config @@ -21,13 +23,13 @@ var exitCh chan int func configure() { var smtpbindaddr, httpbindaddr, hostname, storage_type, mongouri, mongodb, mongocoll string - flag.StringVar(&smtpbindaddr, "smtpbindaddr", "0.0.0.0:1025", "SMTP bind interface and port, e.g. 0.0.0.0:1025 or just :1025") - flag.StringVar(&httpbindaddr, "httpbindaddr", "0.0.0.0:8025", "HTTP bind interface and port, e.g. 0.0.0.0:8025 or just :8025") - flag.StringVar(&hostname, "hostname", "mailhog.example", "Hostname for EHLO/HELO response, e.g. mailhog.example") - flag.StringVar(&storage_type, "storage", "memory", "Message storage: memory (default) or mongodb") - flag.StringVar(&mongouri, "mongouri", "127.0.0.1:27017", "MongoDB URI, e.g. 127.0.0.1:27017") - flag.StringVar(&mongodb, "mongodb", "mailhog", "MongoDB database, e.g. mailhog") - flag.StringVar(&mongocoll, "mongocoll", "messages", "MongoDB collection, e.g. messages") + flag.StringVar(&smtpbindaddr, "smtpbindaddr", envconf.FromEnvP("MH_SMTP_BIND_ADDR", "0.0.0.0:1025").(string), "SMTP bind interface and port, e.g. 0.0.0.0:1025 or just :1025") + flag.StringVar(&httpbindaddr, "httpbindaddr", envconf.FromEnvP("MH_HTTP_BIND_ADDR", "0.0.0.0:8025").(string), "HTTP bind interface and port, e.g. 0.0.0.0:8025 or just :8025") + flag.StringVar(&hostname, "hostname", envconf.FromEnvP("MH_HOSTNAME", "mailhog.example").(string), "Hostname for EHLO/HELO response, e.g. mailhog.example") + flag.StringVar(&storage_type, "storage", envconf.FromEnvP("MH_STORAGE", "memory").(string), "Message storage: memory (default) or mongodb") + flag.StringVar(&mongouri, "mongouri", envconf.FromEnvP("MH_MONGO_URI", "127.0.0.1:27017").(string), "MongoDB URI, e.g. 127.0.0.1:27017") + flag.StringVar(&mongodb, "mongodb", envconf.FromEnvP("MH_MONGO_DB", "mailhog").(string), "MongoDB database, e.g. mailhog") + flag.StringVar(&mongocoll, "mongocoll", envconf.FromEnvP("MH_MONGO_COLLECTION", "messages").(string), "MongoDB collection, e.g. messages") flag.Parse()