MailHog/main.go
2015-05-26 08:55:34 +01:00

85 lines
2 KiB
Go

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)
}
}
}
/*
Add some random content to the end of this file, hopefully tricking GitHub
into recognising this as a Go repo instead of Makefile.
A gopher, ASCII art style - borrowed from
https://gist.github.com/belbomemo/b5e7dad10fa567a5fe8a
,_---~~~~~----._
_,,_,*^____ _____``*g*\"*,
/ __/ /' ^. / \ ^@q f
[ @f | @)) | | @)) l 0 _/
\`/ \~____ / __ \_____/ \
| _l__l_ I
} [______] I
] | | | |
] ~ ~ |
| |
| |
*/