moving frameworks
This commit is contained in:
parent
2d0c451f85
commit
edaa63364d
47
main.go
47
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)
|
||||
}
|
||||
|
|
17
server.go
17
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
|
||||
}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue