1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 17:47:03 +00:00
Files
go-inbucket/inbucket.go
James Hillyerd 5833bb0701 Add expvar JSON @ /debug/vars
Counters include:
 - Uptime
 - SMTP connections
 - SMTP connections (current)
 - SMTP messages delivered
2012-10-23 09:51:30 -07:00

63 lines
1.0 KiB
Go

/*
This is the inbucket daemon launcher
*/
package main
import (
"expvar"
"flag"
"fmt"
"github.com/jhillyerd/inbucket/config"
"github.com/jhillyerd/inbucket/log"
"github.com/jhillyerd/inbucket/smtpd"
"github.com/jhillyerd/inbucket/web"
"os"
"time"
)
var help = flag.Bool("help", false, "Displays this help")
var startTime = time.Now()
func main() {
flag.Parse()
if *help {
flag.Usage()
return
}
// Load & Parse config
if flag.NArg() != 1 {
flag.Usage()
os.Exit(1)
}
err := config.LoadConfig(flag.Arg(0))
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to parse config: %v\n", err)
os.Exit(1)
}
// Configure logging
level, _ := config.Config.String("logging", "level")
log.SetLogLevel(level)
// Startup SMTP server
server := smtpd.New()
go server.Start()
web.Start()
}
func init() {
flag.Usage = func() {
fmt.Fprintln(os.Stderr, "Usage of inbucket [options] <conf file>:")
flag.PrintDefaults()
}
expvar.Publish("uptime", expvar.Func(uptime))
}
func uptime() interface{} {
return time.Since(startTime) / time.Second
}