merp/main.go

50 lines
1.0 KiB
Go
Raw Normal View History

2019-10-03 19:30:04 +00:00
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
package main
2019-10-25 12:01:38 +00:00
import "golang.org/x/crypto/ssh/terminal"
import "github.com/rs/zerolog"
import "github.com/rs/zerolog/log"
import "flag"
2019-10-03 19:30:04 +00:00
var Version string
var Buildtime string
var Builduser string
var Buildarch string
2019-10-25 12:01:38 +00:00
var Appname string = "pooteeweet"
2019-10-03 19:30:04 +00:00
func main() {
2019-10-25 12:01:38 +00:00
debug := flag.Bool("debug", false, "sets log level to debug")
flag.Parse()
initLogging(*debug)
identify()
2019-10-03 19:30:04 +00:00
serve()
}
2019-10-25 12:01:38 +00:00
func identify() {
log.Info().
Str("app", Appname).
Str("version", Version).
Str("buildarch", Buildarch).
Str("buildtime", Buildtime).
Str("builduser", Builduser).
Msg("starting")
2019-10-03 19:30:04 +00:00
}
2019-10-25 12:01:38 +00:00
func initLogging(debug bool) {
log.Logger = log.With().Caller().Logger()
if terminal.IsTerminal(int(os.Stdout.Fd())) {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
}
2019-10-03 19:30:04 +00:00
2019-10-25 12:01:38 +00:00
zerolog.SetGlobalLevel(zerolog.InfoLevel)
if debug {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
t
}
2019-10-03 19:30:04 +00:00
}
2019-10-25 12:01:38 +00:00
func serve() {
server := setupHttpServer()
log.Fatal(server.ListenAndServe())
2019-10-03 19:30:04 +00:00
}