From edaa63364d8e806e86eaddab2407741739424881 Mon Sep 17 00:00:00 2001 From: Jeffrey Paul Date: Fri, 25 Oct 2019 05:01:38 -0700 Subject: [PATCH] moving frameworks --- main.go | 47 ++++++++++++++++++++++++++++++----------------- server.go | 17 ++++++++++++++--- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/main.go b/main.go index 52fff1e..1535c71 100644 --- a/main.go +++ b/main.go @@ -1,36 +1,49 @@ //3456789112345676892123456789312345678941234567895123456789612345678971234567898 package main -import "github.com/sirupsen/logrus" +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 log *logrus.Logger +var Appname string = "pooteeweet" func main() { - initLogging() + debug := flag.Bool("debug", false, "sets log level to debug") + flag.Parse() + initLogging(*debug) + identify() serve() } -func initLogging() { - log = logrus.New() - log.SetReportCaller(true) - log.SetLevel(logrus.DebugLevel) - log.SetFormatter(UTCFormatter{&logrus.JSONFormatter{}}) +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()) } - -type UTCFormatter struct { - logrus.Formatter -} - -func (u UTCFormatter) Format(e *logrus.Entry) ([]byte, error) { - e.Time = e.Time.UTC() - return u.Formatter.Format(e) -} diff --git a/server.go b/server.go index fd5d4cc..d8fbe16 100644 --- a/server.go +++ b/server.go @@ -4,11 +4,21 @@ package main import "flag" import "net/http" import "time" +import "github.com/hoisie/web" +import "golang.org/x/crypto/ssh/terminal" -import "github.com/gorilla/mux" -import "github.com/justinas/alice" -import "github.com/sirupsen/logrus" +func hello(ctx *web.Context, val string) { + for k, v := range ctx.Params { + println(k, v) + } +} +func main() { + web.Get("/(.*)", hello) + web.Run("0.0.0.0:9999") +} + +/* func LoggerMiddleware(h http.Handler) http.Handler { return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { startTime := time.Now().UTC() @@ -49,3 +59,4 @@ func setupHttpServer() *http.Server { } return listener } +*/