MailHog/main.go

62 lines
1.3 KiB
Go
Raw Normal View History

2014-04-16 22:29:23 +00:00
package main
import (
"flag"
2014-10-29 16:59:59 +00:00
"os"
"github.com/ian-kent/go-log/log"
gotcha "github.com/ian-kent/gotcha/app"
"github.com/mailhog/MailHog-Server/api"
2014-12-24 18:31:29 +00:00
cfgapi "github.com/mailhog/MailHog-Server/config"
"github.com/mailhog/MailHog-Server/smtp"
"github.com/mailhog/MailHog-UI/assets"
2014-12-24 18:31:29 +00:00
cfgui "github.com/mailhog/MailHog-UI/config"
"github.com/mailhog/MailHog-UI/web"
2014-12-24 17:12:22 +00:00
"github.com/mailhog/http"
2014-04-16 22:29:23 +00:00
)
2014-12-24 18:31:29 +00:00
var apiconf *cfgapi.Config
var uiconf *cfgui.Config
2014-04-20 14:35:59 +00:00
var exitCh chan int
2014-04-16 22:29:23 +00:00
2014-04-23 23:22:50 +00:00
func configure() {
2014-12-24 18:31:29 +00:00
cfgapi.RegisterFlags()
cfgui.RegisterFlags()
2014-04-16 22:29:23 +00:00
flag.Parse()
2014-12-24 18:31:29 +00:00
apiconf = cfgapi.Configure()
uiconf = cfgui.Configure()
2014-04-16 22:29:23 +00:00
}
func main() {
2014-04-23 23:22:50 +00:00
configure()
2014-04-16 22:29:23 +00:00
2014-04-20 14:35:59 +00:00
exitCh = make(chan int)
2014-12-24 19:25:02 +00:00
if uiconf.UIBindAddr == apiconf.APIBindAddr {
cb := func(app *gotcha.App) {
web.CreateWeb(uiconf, app)
api.CreateAPIv1(apiconf, app)
2014-12-27 13:53:31 +00:00
api.CreateAPIv2(apiconf, app)
2014-12-24 19:25:02 +00:00
}
go http.Listen(uiconf.UIBindAddr, assets.Asset, exitCh, cb)
} else {
cb1 := func(app *gotcha.App) {
api.CreateAPIv1(apiconf, app)
2014-12-27 13:53:31 +00:00
api.CreateAPIv2(apiconf, app)
2014-12-24 19:25:02 +00:00
}
cb2 := func(app *gotcha.App) {
web.CreateWeb(uiconf, app)
}
go http.Listen(apiconf.APIBindAddr, assets.Asset, exitCh, cb1)
go http.Listen(uiconf.UIBindAddr, assets.Asset, exitCh, cb2)
2014-11-23 15:05:11 +00:00
}
2014-12-24 18:31:29 +00:00
go smtp.Listen(apiconf, exitCh)
2014-04-20 14:35:59 +00:00
for {
select {
case <-exitCh:
log.Printf("Received exit signal")
os.Exit(0)
2014-04-20 14:35:59 +00:00
}
}
}