MCPcopy Create free account
hub / github.com/devfeel/dotweb / Handle

Method Handle

middleware.go:151–176  ·  view source on GitHub ↗
(ctx Context)

Source from the content-addressed store, hash-verified

149}
150
151func (m *RequestLogMiddleware) Handle(ctx Context) error {
152 var timeDuration time.Duration
153 var timeTaken uint64
154 err := m.Next(ctx)
155 if ctx.Items().Exists(ItemKeyHandleDuration) {
156 var errParse error
157 timeDuration, errParse = time.ParseDuration(ctx.Items().GetString(ItemKeyHandleDuration))
158 if errParse != nil {
159 timeTaken = 0
160 } else {
161 timeTaken = uint64(timeDuration / time.Millisecond)
162 }
163 } else {
164 var begin time.Time
165 beginVal, exists := ctx.Items().Get(ItemKeyHandleStartTime)
166 if !exists {
167 begin = time.Now()
168 } else {
169 begin = beginVal.(time.Time)
170 }
171 timeTaken = uint64(time.Now().Sub(begin) / time.Millisecond)
172 }
173 log := ctx.Request().Url() + " " + logContext(ctx, timeTaken)
174 ctx.HttpServer().Logger().Debug(log, LogTarget_HttpRequest)
175 return err
176}
177
178// get default log string
179func logContext(ctx Context, timetaken uint64) string {

Callers

nothing calls this directly

Calls 11

UrlMethod · 0.80
logContextFunction · 0.70
NextMethod · 0.65
ExistsMethod · 0.65
ItemsMethod · 0.65
GetStringMethod · 0.65
GetMethod · 0.65
RequestMethod · 0.65
DebugMethod · 0.65
HttpServerMethod · 0.65
LoggerMethod · 0.45

Tested by

no test coverage detected