add pagination
This commit is contained in:
@ -43,9 +43,9 @@ func setupCoursesHTTP(srv xhttp.Server, router *mux.Router, _ *slog.Logger) {
|
||||
coursesListLearningOnlyPath := makePathTemplate(xhttp.LearningTypePathParam)
|
||||
coursesListFullPath := makePathTemplate(xhttp.LearningTypePathParam, xhttp.ThematicTypePathParam)
|
||||
|
||||
muxHandleFunc(coursesRouter, "/", coursesAPI.Index).Methods(http.MethodGet)
|
||||
muxHandleFunc(coursesRouter, coursesListLearningOnlyPath, coursesAPI.List).Methods(http.MethodGet)
|
||||
muxHandleFunc(coursesRouter, coursesListFullPath, coursesAPI.List).Methods(http.MethodGet)
|
||||
muxHandleFunc(coursesRouter, "index", "/", coursesAPI.Index).Methods(http.MethodGet)
|
||||
muxHandleFunc(coursesRouter, "list_learning", coursesListLearningOnlyPath, coursesAPI.List).Methods(http.MethodGet)
|
||||
muxHandleFunc(coursesRouter, "list_full", coursesListFullPath, coursesAPI.List).Methods(http.MethodGet)
|
||||
}
|
||||
|
||||
func setupHTTP(cfg config.HTTP, srv xhttp.Server, log *slog.Logger) *http.Server {
|
||||
@ -111,6 +111,7 @@ func middlewareTrace() mux.MiddlewareFunc {
|
||||
reqidAttr := attribute.Key("http.request_id")
|
||||
statusAttr := attribute.Key("http.status_code")
|
||||
payloadAttr := attribute.Key("http.payload_size")
|
||||
pathAttr := attribute.Key("http.template_path")
|
||||
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@ -118,7 +119,16 @@ func middlewareTrace() mux.MiddlewareFunc {
|
||||
reqid := xcontext.GetRequestID(ctx)
|
||||
|
||||
var span trace.Span
|
||||
ctx, span = webtracer.Start(ctx, r.URL.String(), trace.WithAttributes(reqidAttr.String(reqid)))
|
||||
route := mux.CurrentRoute(r)
|
||||
hname := route.GetName()
|
||||
hpath, _ := route.GetPathTemplate()
|
||||
ctx, span = webtracer.Start(
|
||||
ctx, "http."+hname,
|
||||
trace.WithAttributes(
|
||||
reqidAttr.String(reqid),
|
||||
pathAttr.String(hpath),
|
||||
),
|
||||
)
|
||||
defer span.End()
|
||||
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
@ -131,6 +141,8 @@ func middlewareTrace() mux.MiddlewareFunc {
|
||||
)
|
||||
if statusCode > 399 {
|
||||
span.SetStatus(codes.Error, "error during request")
|
||||
} else {
|
||||
span.SetStatus(codes.Ok, "request completed")
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user