Useful default implementations of the RequestWrapper
interface defined in
vulpine-io/midl.
Includes an implemenation of RequestWrapper
that uses
logrus for logging.
$ go get github.com/vulpine-io/midl-wrappers/logging/logrus
package main
import (
"github.com/sirupsen/logrus"
"github.com/vulpine-io/midl/v1/pkg/midl"
"github.com/vulpine-io/midl-wrappers/logging/logrus/v1/pkg/midllog"
)
func main() {
reqLogger := midllog.NewSimpleLogger()
serv := midl.JSONAdapter().
AddWrappers(midllog.NewLogEntryWrapper(
logrus.WithField("foo", "bar"),
reqLogger,
reqLogger))
}
A simple wrapper that records the time a request started and finished including all middleware and any wrappers appended to the midl.Adapter after the timer.
$ go get github.com/vulpine-io/midl-wrappers/timing
package main
import (
"github.com/sirupsen/logrus"
"github.com/vulpine-io/midl/v1/pkg/midl"
"github.com/vulpine-io/midl-wrappers/timing/v1/pkg/midltime"
)
func main() {
cb := midltime.TimingCallbackFn(func(timing midltime.Timing) {
duration := timing.End.Sub(timing.Start)
// Do something with the time
})
serv := midl.JSONAdapter().
AddWrappers(midltime.NewTimingWrapper(cb))
}