Configure from environment

This commit is contained in:
Ian Kent 2014-10-29 16:59:59 +00:00
parent 5e34255a1d
commit 27cf35d185
4 changed files with 26 additions and 23 deletions

View file

@ -18,6 +18,7 @@ fmt:
deps: deps:
go get github.com/ian-kent/gotcha/... go get github.com/ian-kent/gotcha/...
go get github.com/ian-kent/go-log/log 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 github.com/jteeuwen/go-bindata/...
go get labix.org/v2/mgo go get labix.org/v2/mgo

View file

@ -39,17 +39,17 @@ on port 8025, and in-memory message storage will be used.
### Configuration ### 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 | Environment | Command line | Default | Description
| ------------- | --------------- | ----------- | ------------------- | ------------- | --------------- | -----------
| -hostname | mailhog.example | Hostname to use for EHLO/HELO and message IDs | MH_HOSTNAME | -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 | MH_HTTP_BIND_ADDR | -httpbindaddr | 0.0.0.0:8025 | Interface and port for HTTP server to bind to
| -mongocoll | messages | MongoDB collection name for message storage | MH_MONGO_COLLECTION | -mongocoll | messages | MongoDB collection name for message storage
| -mongodb | mailhog | MongoDB database name for message storage | MH_MONGO_DB | -mongodb | mailhog | MongoDB database name for message storage
| -mongouri | 127.0.0.1:27017 | MongoDB host and port | MH_MONGO_URI | -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 | MH_SMTP_BIND_ADDR | -smtpbindaddr | 0.0.0.0:1025 | Interface and port for SMTP server to bind to
| -storage | memory | Set message storage: memory / mongodb | MH_STORAGE | -storage | memory | Set message storage: memory / mongodb
### Contributing ### Contributing

View file

@ -1038,10 +1038,6 @@ type _bintree_t struct {
var _bintree = &_bintree_t{nil, map[string]*_bintree_t{ var _bintree = &_bintree_t{nil, map[string]*_bintree_t{
"assets": &_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{ "images": &_bintree_t{nil, map[string]*_bintree_t{
"ajax-loader.gif": &_bintree_t{assets_images_ajax_loader_gif, 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{}}, "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{ "js": &_bintree_t{nil, map[string]*_bintree_t{
"controllers.js": &_bintree_t{assets_js_controllers_js, 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{}},
}},
}}, }},
}} }}

20
main.go
View file

@ -2,17 +2,19 @@ package main
import ( import (
"flag" "flag"
"net"
"os"
"github.com/ian-kent/Go-MailHog/mailhog/config" "github.com/ian-kent/Go-MailHog/mailhog/config"
mhhttp "github.com/ian-kent/Go-MailHog/mailhog/http" 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/http/api"
"github.com/ian-kent/Go-MailHog/mailhog/smtp" "github.com/ian-kent/Go-MailHog/mailhog/smtp"
"github.com/ian-kent/Go-MailHog/mailhog/storage" "github.com/ian-kent/Go-MailHog/mailhog/storage"
"github.com/ian-kent/envconf"
"github.com/ian-kent/go-log/log" "github.com/ian-kent/go-log/log"
gotcha "github.com/ian-kent/gotcha/app" gotcha "github.com/ian-kent/gotcha/app"
"github.com/ian-kent/gotcha/events" "github.com/ian-kent/gotcha/events"
"github.com/ian-kent/gotcha/http" "github.com/ian-kent/gotcha/http"
"net"
"os"
) )
var conf *config.Config var conf *config.Config
@ -21,13 +23,13 @@ var exitCh chan int
func configure() { func configure() {
var smtpbindaddr, httpbindaddr, hostname, storage_type, mongouri, mongodb, mongocoll string 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(&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", "0.0.0.0:8025", "HTTP bind interface and port, e.g. 0.0.0.0:8025 or just :8025") 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", "mailhog.example", "Hostname for EHLO/HELO response, e.g. mailhog.example") 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", "memory", "Message storage: memory (default) or mongodb") flag.StringVar(&storage_type, "storage", envconf.FromEnvP("MH_STORAGE", "memory").(string), "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(&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", "mailhog", "MongoDB database, e.g. mailhog") flag.StringVar(&mongodb, "mongodb", envconf.FromEnvP("MH_MONGO_DB", "mailhog").(string), "MongoDB database, e.g. mailhog")
flag.StringVar(&mongocoll, "mongocoll", "messages", "MongoDB collection, e.g. messages") flag.StringVar(&mongocoll, "mongocoll", envconf.FromEnvP("MH_MONGO_COLLECTION", "messages").(string), "MongoDB collection, e.g. messages")
flag.Parse() flag.Parse()