moving frameworks

This commit is contained in:
Jeffrey Paul 2019-10-25 05:01:38 -07:00
parent 2d0c451f85
commit edaa63364d
2 changed files with 44 additions and 20 deletions

47
main.go
View File

@ -1,36 +1,49 @@
//3456789112345676892123456789312345678941234567895123456789612345678971234567898 //3456789112345676892123456789312345678941234567895123456789612345678971234567898
package main 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 Version string
var Buildtime string var Buildtime string
var Builduser string var Builduser string
var Buildarch string var Buildarch string
var log *logrus.Logger var Appname string = "pooteeweet"
func main() { func main() {
initLogging() debug := flag.Bool("debug", false, "sets log level to debug")
flag.Parse()
initLogging(*debug)
identify()
serve() serve()
} }
func initLogging() { func identify() {
log = logrus.New() log.Info().
log.SetReportCaller(true) Str("app", Appname).
log.SetLevel(logrus.DebugLevel) Str("version", Version).
log.SetFormatter(UTCFormatter{&logrus.JSONFormatter{}}) 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() { func serve() {
server := setupHttpServer() server := setupHttpServer()
log.Fatal(server.ListenAndServe()) 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)
}

View File

@ -4,11 +4,21 @@ package main
import "flag" import "flag"
import "net/http" import "net/http"
import "time" import "time"
import "github.com/hoisie/web"
import "golang.org/x/crypto/ssh/terminal"
import "github.com/gorilla/mux" func hello(ctx *web.Context, val string) {
import "github.com/justinas/alice" for k, v := range ctx.Params {
import "github.com/sirupsen/logrus" println(k, v)
}
}
func main() {
web.Get("/(.*)", hello)
web.Run("0.0.0.0:9999")
}
/*
func LoggerMiddleware(h http.Handler) http.Handler { func LoggerMiddleware(h http.Handler) http.Handler {
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
startTime := time.Now().UTC() startTime := time.Now().UTC()
@ -49,3 +59,4 @@ func setupHttpServer() *http.Server {
} }
return listener return listener
} }
*/