package main import ( "flag" "os" gohttp "net/http" "github.com/gorilla/pat" "github.com/ian-kent/go-log/log" "github.com/mailhog/MailHog-Server/api" cfgapi "github.com/mailhog/MailHog-Server/config" "github.com/mailhog/MailHog-Server/smtp" "github.com/mailhog/MailHog-UI/assets" cfgui "github.com/mailhog/MailHog-UI/config" "github.com/mailhog/MailHog-UI/web" "github.com/mailhog/http" ) var apiconf *cfgapi.Config var uiconf *cfgui.Config var exitCh chan int func configure() { cfgapi.RegisterFlags() cfgui.RegisterFlags() flag.Parse() apiconf = cfgapi.Configure() uiconf = cfgui.Configure() } func main() { configure() exitCh = make(chan int) if uiconf.UIBindAddr == apiconf.APIBindAddr { cb := func(r gohttp.Handler) { web.CreateWeb(uiconf, r.(*pat.Router), assets.Asset) api.CreateAPIv1(apiconf, r.(*pat.Router)) api.CreateAPIv2(apiconf, r.(*pat.Router)) } go http.Listen(uiconf.UIBindAddr, assets.Asset, exitCh, cb) } else { cb1 := func(r gohttp.Handler) { api.CreateAPIv1(apiconf, r.(*pat.Router)) api.CreateAPIv2(apiconf, r.(*pat.Router)) } cb2 := func(r gohttp.Handler) { web.CreateWeb(uiconf, r.(*pat.Router), assets.Asset) } go http.Listen(apiconf.APIBindAddr, assets.Asset, exitCh, cb1) go http.Listen(uiconf.UIBindAddr, assets.Asset, exitCh, cb2) } go smtp.Listen(apiconf, exitCh) for { select { case <-exitCh: log.Printf("Received exit signal") os.Exit(0) } } }