package log import ( "context" "io" "time" kitlog "github.com/go-kit/log" "tildegit.org/tjp/gus/gemini" ) func Requests(out io.Writer, logger kitlog.Logger) gemini.Middleware { if logger == nil { logger = kitlog.NewLogfmtLogger(kitlog.NewSyncWriter(out)) } return func(next gemini.Handler) gemini.Handler { return func(ctx context.Context, r *gemini.Request) (resp *gemini.Response) { start := time.Now() defer func() { end := time.Now() logger.Log( "msg", "request", "ts", end, "dur", end.Sub(start), "url", r.URL, "status", resp.Status, ) }() return next(ctx, r) } } }