1
0
mirror of https://github.com/raseels-repos/golang-saas-starter-kit.git synced 2025-06-06 23:46:29 +02:00
Lee Brown 227af02f31 issue#16 web-app account signup
Account signup works with validation and translations.
2019-07-31 13:47:30 -08:00

49 lines
1.2 KiB
Go

package mid
import (
"context"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/webcontext"
"log"
"net/http"
"time"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
// Logger writes some information about the request to the logs in the
// format: TraceID : (200) GET /foo -> IP ADDR (latency)
func Logger(log *log.Logger) web.Middleware {
// This is the actual middleware function to be executed.
f := func(before web.Handler) web.Handler {
// Create the handler that will be attached in the middleware chain.
h := func(ctx context.Context, w http.ResponseWriter, r *http.Request, params map[string]string) error {
span, ctx := tracer.StartSpanFromContext(ctx, "internal.mid.Logger")
defer span.Finish()
v, err := webcontext.ContextValues(ctx)
if err != nil {
return err
}
err = before(ctx, w, r, params)
log.Printf("%d : (%d) : %s %s -> %s (%s)\n",
span.Context().TraceID(),
v.StatusCode,
r.Method, r.URL.Path,
r.RemoteAddr, time.Since(v.Now),
)
// Return the error so it can be handled further up the chain.
return err
}
return h
}
return f
}