50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
|
|
package main
|
|
|
|
import "golang.org/x/crypto/ssh/terminal"
|
|
import "github.com/rs/zerolog"
|
|
import "github.com/rs/zerolog/log"
|
|
import "flag"
|
|
|
|
var Version string
|
|
var Buildtime string
|
|
var Builduser string
|
|
var Buildarch string
|
|
var Appname string = "pooteeweet"
|
|
|
|
func main() {
|
|
debug := flag.Bool("debug", false, "sets log level to debug")
|
|
flag.Parse()
|
|
initLogging(*debug)
|
|
identify()
|
|
serve()
|
|
}
|
|
|
|
func identify() {
|
|
log.Info().
|
|
Str("app", Appname).
|
|
Str("version", Version).
|
|
Str("buildarch", Buildarch).
|
|
Str("buildtime", Buildtime).
|
|
Str("builduser", Builduser).
|
|
Msg("starting")
|
|
}
|
|
|
|
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})
|
|
}
|
|
|
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
|
if debug {
|
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
|
t
|
|
}
|
|
}
|
|
|
|
func serve() {
|
|
server := setupHttpServer()
|
|
log.Fatal(server.ListenAndServe())
|
|
}
|