// Code generated by ogen, DO NOT EDIT. package openapi import ( "context" "net/http" "time" "github.com/go-faster/errors" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/metric" semconv "go.opentelemetry.io/otel/semconv/v1.19.0" "go.opentelemetry.io/otel/trace" ht "github.com/ogen-go/ogen/http" "github.com/ogen-go/ogen/middleware" "github.com/ogen-go/ogen/ogenerrors" ) // handleGroupsGetRequest handles GET /groups operation. // // Get all groups. // // GET /groups func (s *Server) handleGroupsGetRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { otelAttrs := []attribute.KeyValue{ semconv.HTTPMethodKey.String("GET"), semconv.HTTPRouteKey.String("/groups"), } // Start a span for this request. ctx, span := s.cfg.Tracer.Start(r.Context(), "GroupsGet", trace.WithAttributes(otelAttrs...), serverSpanKind, ) defer span.End() // Run stopwatch. startTime := time.Now() defer func() { elapsedDuration := time.Since(startTime) // Use floating point division here for higher precision (instead of Millisecond method). s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) }() // Increment request counter. s.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) var ( recordError = func(stage string, err error) { span.RecordError(err) span.SetStatus(codes.Error, stage) s.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) } err error ) var response []Group if m := s.cfg.Middleware; m != nil { mreq := middleware.Request{ Context: ctx, OperationName: "GroupsGet", OperationSummary: "", OperationID: "", Body: nil, Params: middleware.Parameters{}, Raw: r, } type ( Request = struct{} Params = struct{} Response = []Group ) response, err = middleware.HookMiddleware[ Request, Params, Response, ]( m, mreq, nil, func(ctx context.Context, request Request, params Params) (response Response, err error) { response, err = s.h.GroupsGet(ctx) return response, err }, ) } else { response, err = s.h.GroupsGet(ctx) } if err != nil { if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { if err := encodeErrorResponse(errRes, w, span); err != nil { recordError("Internal", err) } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { recordError("Internal", err) } return } if err := encodeGroupsGetResponse(response, w, span); err != nil { recordError("EncodeResponse", err) if !errors.Is(err, ht.ErrInternalServerErrorResponse) { s.cfg.ErrorHandler(ctx, w, r, err) } return } } // handleGroupsIDDeleteRequest handles DELETE /groups/{id} operation. // // Delete group by id. // // DELETE /groups/{id} func (s *Server) handleGroupsIDDeleteRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { otelAttrs := []attribute.KeyValue{ semconv.HTTPMethodKey.String("DELETE"), semconv.HTTPRouteKey.String("/groups/{id}"), } // Start a span for this request. ctx, span := s.cfg.Tracer.Start(r.Context(), "GroupsIDDelete", trace.WithAttributes(otelAttrs...), serverSpanKind, ) defer span.End() // Run stopwatch. startTime := time.Now() defer func() { elapsedDuration := time.Since(startTime) // Use floating point division here for higher precision (instead of Millisecond method). s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) }() // Increment request counter. s.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) var ( recordError = func(stage string, err error) { span.RecordError(err) span.SetStatus(codes.Error, stage) s.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) } err error opErrContext = ogenerrors.OperationContext{ Name: "GroupsIDDelete", ID: "", } ) params, err := decodeGroupsIDDeleteParams(args, argsEscaped, r) if err != nil { err = &ogenerrors.DecodeParamsError{ OperationContext: opErrContext, Err: err, } recordError("DecodeParams", err) s.cfg.ErrorHandler(ctx, w, r, err) return } var response GroupsIDDeleteRes if m := s.cfg.Middleware; m != nil { mreq := middleware.Request{ Context: ctx, OperationName: "GroupsIDDelete", OperationSummary: "", OperationID: "", Body: nil, Params: middleware.Parameters{ { Name: "id", In: "path", }: params.ID, }, Raw: r, } type ( Request = struct{} Params = GroupsIDDeleteParams Response = GroupsIDDeleteRes ) response, err = middleware.HookMiddleware[ Request, Params, Response, ]( m, mreq, unpackGroupsIDDeleteParams, func(ctx context.Context, request Request, params Params) (response Response, err error) { response, err = s.h.GroupsIDDelete(ctx, params) return response, err }, ) } else { response, err = s.h.GroupsIDDelete(ctx, params) } if err != nil { if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { if err := encodeErrorResponse(errRes, w, span); err != nil { recordError("Internal", err) } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { recordError("Internal", err) } return } if err := encodeGroupsIDDeleteResponse(response, w, span); err != nil { recordError("EncodeResponse", err) if !errors.Is(err, ht.ErrInternalServerErrorResponse) { s.cfg.ErrorHandler(ctx, w, r, err) } return } } // handleGroupsIDGetRequest handles GET /groups/{id} operation. // // Get group by id. // // GET /groups/{id} func (s *Server) handleGroupsIDGetRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { otelAttrs := []attribute.KeyValue{ semconv.HTTPMethodKey.String("GET"), semconv.HTTPRouteKey.String("/groups/{id}"), } // Start a span for this request. ctx, span := s.cfg.Tracer.Start(r.Context(), "GroupsIDGet", trace.WithAttributes(otelAttrs...), serverSpanKind, ) defer span.End() // Run stopwatch. startTime := time.Now() defer func() { elapsedDuration := time.Since(startTime) // Use floating point division here for higher precision (instead of Millisecond method). s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) }() // Increment request counter. s.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) var ( recordError = func(stage string, err error) { span.RecordError(err) span.SetStatus(codes.Error, stage) s.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) } err error opErrContext = ogenerrors.OperationContext{ Name: "GroupsIDGet", ID: "", } ) params, err := decodeGroupsIDGetParams(args, argsEscaped, r) if err != nil { err = &ogenerrors.DecodeParamsError{ OperationContext: opErrContext, Err: err, } recordError("DecodeParams", err) s.cfg.ErrorHandler(ctx, w, r, err) return } var response GroupsIDGetRes if m := s.cfg.Middleware; m != nil { mreq := middleware.Request{ Context: ctx, OperationName: "GroupsIDGet", OperationSummary: "", OperationID: "", Body: nil, Params: middleware.Parameters{ { Name: "id", In: "path", }: params.ID, }, Raw: r, } type ( Request = struct{} Params = GroupsIDGetParams Response = GroupsIDGetRes ) response, err = middleware.HookMiddleware[ Request, Params, Response, ]( m, mreq, unpackGroupsIDGetParams, func(ctx context.Context, request Request, params Params) (response Response, err error) { response, err = s.h.GroupsIDGet(ctx, params) return response, err }, ) } else { response, err = s.h.GroupsIDGet(ctx, params) } if err != nil { if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { if err := encodeErrorResponse(errRes, w, span); err != nil { recordError("Internal", err) } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { recordError("Internal", err) } return } if err := encodeGroupsIDGetResponse(response, w, span); err != nil { recordError("EncodeResponse", err) if !errors.Is(err, ht.ErrInternalServerErrorResponse) { s.cfg.ErrorHandler(ctx, w, r, err) } return } } // handleGroupsIDPutRequest handles PUT /groups/{id} operation. // // Update group by id. // // PUT /groups/{id} func (s *Server) handleGroupsIDPutRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { otelAttrs := []attribute.KeyValue{ semconv.HTTPMethodKey.String("PUT"), semconv.HTTPRouteKey.String("/groups/{id}"), } // Start a span for this request. ctx, span := s.cfg.Tracer.Start(r.Context(), "GroupsIDPut", trace.WithAttributes(otelAttrs...), serverSpanKind, ) defer span.End() // Run stopwatch. startTime := time.Now() defer func() { elapsedDuration := time.Since(startTime) // Use floating point division here for higher precision (instead of Millisecond method). s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) }() // Increment request counter. s.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) var ( recordError = func(stage string, err error) { span.RecordError(err) span.SetStatus(codes.Error, stage) s.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) } err error opErrContext = ogenerrors.OperationContext{ Name: "GroupsIDPut", ID: "", } ) params, err := decodeGroupsIDPutParams(args, argsEscaped, r) if err != nil { err = &ogenerrors.DecodeParamsError{ OperationContext: opErrContext, Err: err, } recordError("DecodeParams", err) s.cfg.ErrorHandler(ctx, w, r, err) return } request, close, err := s.decodeGroupsIDPutRequest(r) if err != nil { err = &ogenerrors.DecodeRequestError{ OperationContext: opErrContext, Err: err, } recordError("DecodeRequest", err) s.cfg.ErrorHandler(ctx, w, r, err) return } defer func() { if err := close(); err != nil { recordError("CloseRequest", err) } }() var response GroupsIDPutRes if m := s.cfg.Middleware; m != nil { mreq := middleware.Request{ Context: ctx, OperationName: "GroupsIDPut", OperationSummary: "", OperationID: "", Body: request, Params: middleware.Parameters{ { Name: "id", In: "path", }: params.ID, }, Raw: r, } type ( Request = *GroupUpdate Params = GroupsIDPutParams Response = GroupsIDPutRes ) response, err = middleware.HookMiddleware[ Request, Params, Response, ]( m, mreq, unpackGroupsIDPutParams, func(ctx context.Context, request Request, params Params) (response Response, err error) { response, err = s.h.GroupsIDPut(ctx, request, params) return response, err }, ) } else { response, err = s.h.GroupsIDPut(ctx, request, params) } if err != nil { if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { if err := encodeErrorResponse(errRes, w, span); err != nil { recordError("Internal", err) } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { recordError("Internal", err) } return } if err := encodeGroupsIDPutResponse(response, w, span); err != nil { recordError("EncodeResponse", err) if !errors.Is(err, ht.ErrInternalServerErrorResponse) { s.cfg.ErrorHandler(ctx, w, r, err) } return } } // handleGroupsPostRequest handles POST /groups operation. // // Create group. // // POST /groups func (s *Server) handleGroupsPostRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { otelAttrs := []attribute.KeyValue{ semconv.HTTPMethodKey.String("POST"), semconv.HTTPRouteKey.String("/groups"), } // Start a span for this request. ctx, span := s.cfg.Tracer.Start(r.Context(), "GroupsPost", trace.WithAttributes(otelAttrs...), serverSpanKind, ) defer span.End() // Run stopwatch. startTime := time.Now() defer func() { elapsedDuration := time.Since(startTime) // Use floating point division here for higher precision (instead of Millisecond method). s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) }() // Increment request counter. s.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) var ( recordError = func(stage string, err error) { span.RecordError(err) span.SetStatus(codes.Error, stage) s.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) } err error opErrContext = ogenerrors.OperationContext{ Name: "GroupsPost", ID: "", } ) request, close, err := s.decodeGroupsPostRequest(r) if err != nil { err = &ogenerrors.DecodeRequestError{ OperationContext: opErrContext, Err: err, } recordError("DecodeRequest", err) s.cfg.ErrorHandler(ctx, w, r, err) return } defer func() { if err := close(); err != nil { recordError("CloseRequest", err) } }() var response *Group if m := s.cfg.Middleware; m != nil { mreq := middleware.Request{ Context: ctx, OperationName: "GroupsPost", OperationSummary: "", OperationID: "", Body: request, Params: middleware.Parameters{}, Raw: r, } type ( Request = *GroupUpdate Params = struct{} Response = *Group ) response, err = middleware.HookMiddleware[ Request, Params, Response, ]( m, mreq, nil, func(ctx context.Context, request Request, params Params) (response Response, err error) { response, err = s.h.GroupsPost(ctx, request) return response, err }, ) } else { response, err = s.h.GroupsPost(ctx, request) } if err != nil { if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { if err := encodeErrorResponse(errRes, w, span); err != nil { recordError("Internal", err) } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { recordError("Internal", err) } return } if err := encodeGroupsPostResponse(response, w, span); err != nil { recordError("EncodeResponse", err) if !errors.Is(err, ht.ErrInternalServerErrorResponse) { s.cfg.ErrorHandler(ctx, w, r, err) } return } } // handleHealthzGetRequest handles GET /healthz operation. // // GET /healthz func (s *Server) handleHealthzGetRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { otelAttrs := []attribute.KeyValue{ semconv.HTTPMethodKey.String("GET"), semconv.HTTPRouteKey.String("/healthz"), } // Start a span for this request. ctx, span := s.cfg.Tracer.Start(r.Context(), "HealthzGet", trace.WithAttributes(otelAttrs...), serverSpanKind, ) defer span.End() // Run stopwatch. startTime := time.Now() defer func() { elapsedDuration := time.Since(startTime) // Use floating point division here for higher precision (instead of Millisecond method). s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) }() // Increment request counter. s.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) var ( recordError = func(stage string, err error) { span.RecordError(err) span.SetStatus(codes.Error, stage) s.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) } err error ) var response *Ok if m := s.cfg.Middleware; m != nil { mreq := middleware.Request{ Context: ctx, OperationName: "HealthzGet", OperationSummary: "", OperationID: "", Body: nil, Params: middleware.Parameters{}, Raw: r, } type ( Request = struct{} Params = struct{} Response = *Ok ) response, err = middleware.HookMiddleware[ Request, Params, Response, ]( m, mreq, nil, func(ctx context.Context, request Request, params Params) (response Response, err error) { response, err = s.h.HealthzGet(ctx) return response, err }, ) } else { response, err = s.h.HealthzGet(ctx) } if err != nil { if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { if err := encodeErrorResponse(errRes, w, span); err != nil { recordError("Internal", err) } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { recordError("Internal", err) } return } if err := encodeHealthzGetResponse(response, w, span); err != nil { recordError("EncodeResponse", err) if !errors.Is(err, ht.ErrInternalServerErrorResponse) { s.cfg.ErrorHandler(ctx, w, r, err) } return } } // handleUsersGetRequest handles GET /users operation. // // Get all users. // // GET /users func (s *Server) handleUsersGetRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { otelAttrs := []attribute.KeyValue{ semconv.HTTPMethodKey.String("GET"), semconv.HTTPRouteKey.String("/users"), } // Start a span for this request. ctx, span := s.cfg.Tracer.Start(r.Context(), "UsersGet", trace.WithAttributes(otelAttrs...), serverSpanKind, ) defer span.End() // Run stopwatch. startTime := time.Now() defer func() { elapsedDuration := time.Since(startTime) // Use floating point division here for higher precision (instead of Millisecond method). s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) }() // Increment request counter. s.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) var ( recordError = func(stage string, err error) { span.RecordError(err) span.SetStatus(codes.Error, stage) s.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) } err error ) var response []User if m := s.cfg.Middleware; m != nil { mreq := middleware.Request{ Context: ctx, OperationName: "UsersGet", OperationSummary: "", OperationID: "", Body: nil, Params: middleware.Parameters{}, Raw: r, } type ( Request = struct{} Params = struct{} Response = []User ) response, err = middleware.HookMiddleware[ Request, Params, Response, ]( m, mreq, nil, func(ctx context.Context, request Request, params Params) (response Response, err error) { response, err = s.h.UsersGet(ctx) return response, err }, ) } else { response, err = s.h.UsersGet(ctx) } if err != nil { if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { if err := encodeErrorResponse(errRes, w, span); err != nil { recordError("Internal", err) } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { recordError("Internal", err) } return } if err := encodeUsersGetResponse(response, w, span); err != nil { recordError("EncodeResponse", err) if !errors.Is(err, ht.ErrInternalServerErrorResponse) { s.cfg.ErrorHandler(ctx, w, r, err) } return } } // handleUsersIDDeleteRequest handles DELETE /users/{id} operation. // // Delete user by id. // // DELETE /users/{id} func (s *Server) handleUsersIDDeleteRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { otelAttrs := []attribute.KeyValue{ semconv.HTTPMethodKey.String("DELETE"), semconv.HTTPRouteKey.String("/users/{id}"), } // Start a span for this request. ctx, span := s.cfg.Tracer.Start(r.Context(), "UsersIDDelete", trace.WithAttributes(otelAttrs...), serverSpanKind, ) defer span.End() // Run stopwatch. startTime := time.Now() defer func() { elapsedDuration := time.Since(startTime) // Use floating point division here for higher precision (instead of Millisecond method). s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) }() // Increment request counter. s.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) var ( recordError = func(stage string, err error) { span.RecordError(err) span.SetStatus(codes.Error, stage) s.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) } err error opErrContext = ogenerrors.OperationContext{ Name: "UsersIDDelete", ID: "", } ) params, err := decodeUsersIDDeleteParams(args, argsEscaped, r) if err != nil { err = &ogenerrors.DecodeParamsError{ OperationContext: opErrContext, Err: err, } recordError("DecodeParams", err) s.cfg.ErrorHandler(ctx, w, r, err) return } var response UsersIDDeleteRes if m := s.cfg.Middleware; m != nil { mreq := middleware.Request{ Context: ctx, OperationName: "UsersIDDelete", OperationSummary: "", OperationID: "", Body: nil, Params: middleware.Parameters{ { Name: "id", In: "path", }: params.ID, }, Raw: r, } type ( Request = struct{} Params = UsersIDDeleteParams Response = UsersIDDeleteRes ) response, err = middleware.HookMiddleware[ Request, Params, Response, ]( m, mreq, unpackUsersIDDeleteParams, func(ctx context.Context, request Request, params Params) (response Response, err error) { response, err = s.h.UsersIDDelete(ctx, params) return response, err }, ) } else { response, err = s.h.UsersIDDelete(ctx, params) } if err != nil { if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { if err := encodeErrorResponse(errRes, w, span); err != nil { recordError("Internal", err) } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { recordError("Internal", err) } return } if err := encodeUsersIDDeleteResponse(response, w, span); err != nil { recordError("EncodeResponse", err) if !errors.Is(err, ht.ErrInternalServerErrorResponse) { s.cfg.ErrorHandler(ctx, w, r, err) } return } } // handleUsersIDGetRequest handles GET /users/{id} operation. // // Get user by id. // // GET /users/{id} func (s *Server) handleUsersIDGetRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { otelAttrs := []attribute.KeyValue{ semconv.HTTPMethodKey.String("GET"), semconv.HTTPRouteKey.String("/users/{id}"), } // Start a span for this request. ctx, span := s.cfg.Tracer.Start(r.Context(), "UsersIDGet", trace.WithAttributes(otelAttrs...), serverSpanKind, ) defer span.End() // Run stopwatch. startTime := time.Now() defer func() { elapsedDuration := time.Since(startTime) // Use floating point division here for higher precision (instead of Millisecond method). s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) }() // Increment request counter. s.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) var ( recordError = func(stage string, err error) { span.RecordError(err) span.SetStatus(codes.Error, stage) s.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) } err error opErrContext = ogenerrors.OperationContext{ Name: "UsersIDGet", ID: "", } ) params, err := decodeUsersIDGetParams(args, argsEscaped, r) if err != nil { err = &ogenerrors.DecodeParamsError{ OperationContext: opErrContext, Err: err, } recordError("DecodeParams", err) s.cfg.ErrorHandler(ctx, w, r, err) return } var response UsersIDGetRes if m := s.cfg.Middleware; m != nil { mreq := middleware.Request{ Context: ctx, OperationName: "UsersIDGet", OperationSummary: "", OperationID: "", Body: nil, Params: middleware.Parameters{ { Name: "id", In: "path", }: params.ID, }, Raw: r, } type ( Request = struct{} Params = UsersIDGetParams Response = UsersIDGetRes ) response, err = middleware.HookMiddleware[ Request, Params, Response, ]( m, mreq, unpackUsersIDGetParams, func(ctx context.Context, request Request, params Params) (response Response, err error) { response, err = s.h.UsersIDGet(ctx, params) return response, err }, ) } else { response, err = s.h.UsersIDGet(ctx, params) } if err != nil { if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { if err := encodeErrorResponse(errRes, w, span); err != nil { recordError("Internal", err) } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { recordError("Internal", err) } return } if err := encodeUsersIDGetResponse(response, w, span); err != nil { recordError("EncodeResponse", err) if !errors.Is(err, ht.ErrInternalServerErrorResponse) { s.cfg.ErrorHandler(ctx, w, r, err) } return } } // handleUsersIDGroupPutRequest handles PUT /users/{id}/group operation. // // Update user group by id. // // PUT /users/{id}/group func (s *Server) handleUsersIDGroupPutRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { otelAttrs := []attribute.KeyValue{ semconv.HTTPMethodKey.String("PUT"), semconv.HTTPRouteKey.String("/users/{id}/group"), } // Start a span for this request. ctx, span := s.cfg.Tracer.Start(r.Context(), "UsersIDGroupPut", trace.WithAttributes(otelAttrs...), serverSpanKind, ) defer span.End() // Run stopwatch. startTime := time.Now() defer func() { elapsedDuration := time.Since(startTime) // Use floating point division here for higher precision (instead of Millisecond method). s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) }() // Increment request counter. s.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) var ( recordError = func(stage string, err error) { span.RecordError(err) span.SetStatus(codes.Error, stage) s.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) } err error opErrContext = ogenerrors.OperationContext{ Name: "UsersIDGroupPut", ID: "", } ) params, err := decodeUsersIDGroupPutParams(args, argsEscaped, r) if err != nil { err = &ogenerrors.DecodeParamsError{ OperationContext: opErrContext, Err: err, } recordError("DecodeParams", err) s.cfg.ErrorHandler(ctx, w, r, err) return } request, close, err := s.decodeUsersIDGroupPutRequest(r) if err != nil { err = &ogenerrors.DecodeRequestError{ OperationContext: opErrContext, Err: err, } recordError("DecodeRequest", err) s.cfg.ErrorHandler(ctx, w, r, err) return } defer func() { if err := close(); err != nil { recordError("CloseRequest", err) } }() var response UsersIDGroupPutRes if m := s.cfg.Middleware; m != nil { mreq := middleware.Request{ Context: ctx, OperationName: "UsersIDGroupPut", OperationSummary: "", OperationID: "", Body: request, Params: middleware.Parameters{ { Name: "id", In: "path", }: params.ID, }, Raw: r, } type ( Request = *UsersIDGroupPutReq Params = UsersIDGroupPutParams Response = UsersIDGroupPutRes ) response, err = middleware.HookMiddleware[ Request, Params, Response, ]( m, mreq, unpackUsersIDGroupPutParams, func(ctx context.Context, request Request, params Params) (response Response, err error) { response, err = s.h.UsersIDGroupPut(ctx, request, params) return response, err }, ) } else { response, err = s.h.UsersIDGroupPut(ctx, request, params) } if err != nil { if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { if err := encodeErrorResponse(errRes, w, span); err != nil { recordError("Internal", err) } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { recordError("Internal", err) } return } if err := encodeUsersIDGroupPutResponse(response, w, span); err != nil { recordError("EncodeResponse", err) if !errors.Is(err, ht.ErrInternalServerErrorResponse) { s.cfg.ErrorHandler(ctx, w, r, err) } return } } // handleUsersIDPutRequest handles PUT /users/{id} operation. // // Update user by id. // // PUT /users/{id} func (s *Server) handleUsersIDPutRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { otelAttrs := []attribute.KeyValue{ semconv.HTTPMethodKey.String("PUT"), semconv.HTTPRouteKey.String("/users/{id}"), } // Start a span for this request. ctx, span := s.cfg.Tracer.Start(r.Context(), "UsersIDPut", trace.WithAttributes(otelAttrs...), serverSpanKind, ) defer span.End() // Run stopwatch. startTime := time.Now() defer func() { elapsedDuration := time.Since(startTime) // Use floating point division here for higher precision (instead of Millisecond method). s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) }() // Increment request counter. s.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) var ( recordError = func(stage string, err error) { span.RecordError(err) span.SetStatus(codes.Error, stage) s.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) } err error opErrContext = ogenerrors.OperationContext{ Name: "UsersIDPut", ID: "", } ) params, err := decodeUsersIDPutParams(args, argsEscaped, r) if err != nil { err = &ogenerrors.DecodeParamsError{ OperationContext: opErrContext, Err: err, } recordError("DecodeParams", err) s.cfg.ErrorHandler(ctx, w, r, err) return } request, close, err := s.decodeUsersIDPutRequest(r) if err != nil { err = &ogenerrors.DecodeRequestError{ OperationContext: opErrContext, Err: err, } recordError("DecodeRequest", err) s.cfg.ErrorHandler(ctx, w, r, err) return } defer func() { if err := close(); err != nil { recordError("CloseRequest", err) } }() var response UsersIDPutRes if m := s.cfg.Middleware; m != nil { mreq := middleware.Request{ Context: ctx, OperationName: "UsersIDPut", OperationSummary: "", OperationID: "", Body: request, Params: middleware.Parameters{ { Name: "id", In: "path", }: params.ID, }, Raw: r, } type ( Request = *UserUpdate Params = UsersIDPutParams Response = UsersIDPutRes ) response, err = middleware.HookMiddleware[ Request, Params, Response, ]( m, mreq, unpackUsersIDPutParams, func(ctx context.Context, request Request, params Params) (response Response, err error) { response, err = s.h.UsersIDPut(ctx, request, params) return response, err }, ) } else { response, err = s.h.UsersIDPut(ctx, request, params) } if err != nil { if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { if err := encodeErrorResponse(errRes, w, span); err != nil { recordError("Internal", err) } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { recordError("Internal", err) } return } if err := encodeUsersIDPutResponse(response, w, span); err != nil { recordError("EncodeResponse", err) if !errors.Is(err, ht.ErrInternalServerErrorResponse) { s.cfg.ErrorHandler(ctx, w, r, err) } return } } // handleUsersPostRequest handles POST /users operation. // // Create user. // // POST /users func (s *Server) handleUsersPostRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { otelAttrs := []attribute.KeyValue{ semconv.HTTPMethodKey.String("POST"), semconv.HTTPRouteKey.String("/users"), } // Start a span for this request. ctx, span := s.cfg.Tracer.Start(r.Context(), "UsersPost", trace.WithAttributes(otelAttrs...), serverSpanKind, ) defer span.End() // Run stopwatch. startTime := time.Now() defer func() { elapsedDuration := time.Since(startTime) // Use floating point division here for higher precision (instead of Millisecond method). s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) }() // Increment request counter. s.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) var ( recordError = func(stage string, err error) { span.RecordError(err) span.SetStatus(codes.Error, stage) s.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) } err error opErrContext = ogenerrors.OperationContext{ Name: "UsersPost", ID: "", } ) request, close, err := s.decodeUsersPostRequest(r) if err != nil { err = &ogenerrors.DecodeRequestError{ OperationContext: opErrContext, Err: err, } recordError("DecodeRequest", err) s.cfg.ErrorHandler(ctx, w, r, err) return } defer func() { if err := close(); err != nil { recordError("CloseRequest", err) } }() var response *User if m := s.cfg.Middleware; m != nil { mreq := middleware.Request{ Context: ctx, OperationName: "UsersPost", OperationSummary: "", OperationID: "", Body: request, Params: middleware.Parameters{}, Raw: r, } type ( Request = *UserUpdate Params = struct{} Response = *User ) response, err = middleware.HookMiddleware[ Request, Params, Response, ]( m, mreq, nil, func(ctx context.Context, request Request, params Params) (response Response, err error) { response, err = s.h.UsersPost(ctx, request) return response, err }, ) } else { response, err = s.h.UsersPost(ctx, request) } if err != nil { if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { if err := encodeErrorResponse(errRes, w, span); err != nil { recordError("Internal", err) } return } if errors.Is(err, ht.ErrNotImplemented) { s.cfg.ErrorHandler(ctx, w, r, err) return } if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { recordError("Internal", err) } return } if err := encodeUsersPostResponse(response, w, span); err != nil { recordError("EncodeResponse", err) if !errors.Is(err, ht.ErrInternalServerErrorResponse) { s.cfg.ErrorHandler(ctx, w, r, err) } return } }