1
0
api/ent/ogent/oas_handlers_gen.go

2873 lines
65 KiB
Go
Raw Normal View History

2022-08-31 06:18:14 +00:00
// Code generated by ogen, DO NOT EDIT.
package ogent
import (
"context"
"net/http"
"time"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
2022-08-31 07:49:08 +00:00
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
2022-08-31 06:18:14 +00:00
"go.opentelemetry.io/otel/trace"
2022-08-31 07:49:08 +00:00
"github.com/ogen-go/ogen/middleware"
"github.com/ogen-go/ogen/ogenerrors"
"github.com/ogen-go/ogen/otelogen"
2022-08-31 06:18:14 +00:00
)
2022-08-31 07:49:08 +00:00
// handleCreateCardRequest handles createCard operation.
2022-08-31 06:18:14 +00:00
//
2022-08-31 07:49:08 +00:00
// Creates a new Card and persists it to storage.
//
// POST /cards
func (s *Server) handleCreateCardRequest(args [0]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("createCard"),
semconv.HTTPMethodKey.String("POST"),
semconv.HTTPRouteKey.String("/cards"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "CreateCard",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Run stopwatch.
2022-08-31 06:18:14 +00:00
startTime := time.Now()
2022-08-31 07:49:08 +00:00
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "CreateCard",
ID: "createCard",
}
)
request, close, err := s.decodeCreateCardRequest(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 CreateCardRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "CreateCard",
OperationID: "createCard",
Body: request,
Params: middleware.Parameters{},
Raw: r,
}
type (
Request = *CreateCardReq
Params = struct{}
Response = CreateCardRes
)
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.CreateCard(ctx, request)
return response, err
},
)
} else {
response, err = s.h.CreateCard(ctx, request)
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeCreateCardResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
}
// handleCreateGroupRequest handles createGroup operation.
//
// Creates a new Group and persists it to storage.
//
// POST /groups
func (s *Server) handleCreateGroupRequest(args [0]string, w http.ResponseWriter, r *http.Request) {
2022-08-31 06:18:14 +00:00
otelAttrs := []attribute.KeyValue{
2022-08-31 07:49:08 +00:00
otelogen.OperationID("createGroup"),
semconv.HTTPMethodKey.String("POST"),
semconv.HTTPRouteKey.String("/groups"),
2022-08-31 06:18:14 +00:00
}
2022-08-31 07:49:08 +00:00
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "CreateGroup",
2022-08-31 06:18:14 +00:00
trace.WithAttributes(otelAttrs...),
2022-08-31 07:49:08 +00:00
serverSpanKind,
2022-08-31 06:18:14 +00:00
)
2022-08-31 07:49:08 +00:00
defer span.End()
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
2022-08-31 06:18:14 +00:00
s.requests.Add(ctx, 1, otelAttrs...)
2022-08-31 07:49:08 +00:00
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "CreateGroup",
ID: "createGroup",
}
)
request, close, err := s.decodeCreateGroupRequest(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 CreateGroupRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "CreateGroup",
OperationID: "createGroup",
Body: request,
Params: middleware.Parameters{},
Raw: r,
}
type (
Request = *CreateGroupReq
Params = struct{}
Response = CreateGroupRes
)
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.CreateGroup(ctx, request)
return response, err
},
)
} else {
response, err = s.h.CreateGroup(ctx, request)
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeCreateGroupResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
}
2024-02-03 06:48:28 +00:00
// handleCreateUeRequest handles createUe operation.
//
// Creates a new Ue and persists it to storage.
//
// POST /ues
func (s *Server) handleCreateUeRequest(args [0]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("createUe"),
semconv.HTTPMethodKey.String("POST"),
semconv.HTTPRouteKey.String("/ues"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "CreateUe",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "CreateUe",
ID: "createUe",
}
)
request, close, err := s.decodeCreateUeRequest(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 CreateUeRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "CreateUe",
OperationID: "createUe",
Body: request,
Params: middleware.Parameters{},
Raw: r,
}
type (
Request = *CreateUeReq
Params = struct{}
Response = CreateUeRes
)
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.CreateUe(ctx, request)
return response, err
},
)
} else {
response, err = s.h.CreateUe(ctx, request)
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeCreateUeResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
}
2022-08-31 07:49:08 +00:00
// handleCreateUserRequest handles createUser operation.
//
// Creates a new User and persists it to storage.
//
// POST /users
func (s *Server) handleCreateUserRequest(args [0]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("createUser"),
semconv.HTTPMethodKey.String("POST"),
semconv.HTTPRouteKey.String("/users"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "CreateUser",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
2022-08-31 06:18:14 +00:00
defer span.End()
2022-08-31 07:49:08 +00:00
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "CreateUser",
ID: "createUser",
}
)
request, close, err := s.decodeCreateUserRequest(r)
2022-08-31 06:18:14 +00:00
if err != nil {
2022-08-31 07:49:08 +00:00
err = &ogenerrors.DecodeRequestError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeRequest", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
2022-08-31 07:49:08 +00:00
defer func() {
if err := close(); err != nil {
recordError("CloseRequest", err)
}
}()
2022-08-31 06:18:14 +00:00
2022-08-31 07:49:08 +00:00
var response CreateUserRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "CreateUser",
OperationID: "createUser",
Body: request,
Params: middleware.Parameters{},
Raw: r,
}
type (
Request = *CreateUserReq
Params = struct{}
Response = CreateUserRes
)
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.CreateUser(ctx, request)
return response, err
},
)
} else {
response, err = s.h.CreateUser(ctx, request)
}
2022-08-31 06:18:14 +00:00
if err != nil {
2022-08-31 07:49:08 +00:00
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
2022-08-31 07:49:08 +00:00
if err := encodeCreateUserResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
}
2022-08-31 07:49:08 +00:00
// handleDeleteCardRequest handles deleteCard operation.
2022-08-31 06:18:14 +00:00
//
2022-08-31 07:49:08 +00:00
// Deletes the Card with the requested ID.
//
// DELETE /cards/{id}
func (s *Server) handleDeleteCardRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("deleteCard"),
semconv.HTTPMethodKey.String("DELETE"),
semconv.HTTPRouteKey.String("/cards/{id}"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "DeleteCard",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Run stopwatch.
2022-08-31 06:18:14 +00:00
startTime := time.Now()
2022-08-31 07:49:08 +00:00
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "DeleteCard",
ID: "deleteCard",
}
)
params, err := decodeDeleteCardParams(args, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response DeleteCardRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "DeleteCard",
OperationID: "deleteCard",
Body: nil,
Params: middleware.Parameters{
{
Name: "id",
In: "path",
}: params.ID,
},
Raw: r,
}
type (
Request = struct{}
Params = DeleteCardParams
Response = DeleteCardRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackDeleteCardParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.DeleteCard(ctx, params)
return response, err
},
)
} else {
response, err = s.h.DeleteCard(ctx, params)
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeDeleteCardResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
}
// handleDeleteGroupRequest handles deleteGroup operation.
//
// Deletes the Group with the requested ID.
//
// DELETE /groups/{id}
func (s *Server) handleDeleteGroupRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
2022-08-31 06:18:14 +00:00
otelAttrs := []attribute.KeyValue{
2022-08-31 07:49:08 +00:00
otelogen.OperationID("deleteGroup"),
semconv.HTTPMethodKey.String("DELETE"),
semconv.HTTPRouteKey.String("/groups/{id}"),
2022-08-31 06:18:14 +00:00
}
2022-08-31 07:49:08 +00:00
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "DeleteGroup",
2022-08-31 06:18:14 +00:00
trace.WithAttributes(otelAttrs...),
2022-08-31 07:49:08 +00:00
serverSpanKind,
2022-08-31 06:18:14 +00:00
)
2022-08-31 07:49:08 +00:00
defer span.End()
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
2022-08-31 06:18:14 +00:00
s.requests.Add(ctx, 1, otelAttrs...)
2022-08-31 07:49:08 +00:00
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "DeleteGroup",
ID: "deleteGroup",
}
)
params, err := decodeDeleteGroupParams(args, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response DeleteGroupRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "DeleteGroup",
OperationID: "deleteGroup",
Body: nil,
Params: middleware.Parameters{
{
Name: "id",
In: "path",
}: params.ID,
},
Raw: r,
}
type (
Request = struct{}
Params = DeleteGroupParams
Response = DeleteGroupRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackDeleteGroupParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.DeleteGroup(ctx, params)
return response, err
},
)
} else {
response, err = s.h.DeleteGroup(ctx, params)
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeDeleteGroupResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
}
2024-02-03 06:48:28 +00:00
// handleDeleteUeRequest handles deleteUe operation.
//
// Deletes the Ue with the requested ID.
//
// DELETE /ues/{id}
func (s *Server) handleDeleteUeRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("deleteUe"),
semconv.HTTPMethodKey.String("DELETE"),
semconv.HTTPRouteKey.String("/ues/{id}"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "DeleteUe",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "DeleteUe",
ID: "deleteUe",
}
)
params, err := decodeDeleteUeParams(args, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response DeleteUeRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "DeleteUe",
OperationID: "deleteUe",
Body: nil,
Params: middleware.Parameters{
{
Name: "id",
In: "path",
}: params.ID,
},
Raw: r,
}
type (
Request = struct{}
Params = DeleteUeParams
Response = DeleteUeRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackDeleteUeParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.DeleteUe(ctx, params)
return response, err
},
)
} else {
response, err = s.h.DeleteUe(ctx, params)
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeDeleteUeResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
}
2022-08-31 07:49:08 +00:00
// handleDeleteUserRequest handles deleteUser operation.
//
// Deletes the User with the requested ID.
//
// DELETE /users/{id}
func (s *Server) handleDeleteUserRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("deleteUser"),
semconv.HTTPMethodKey.String("DELETE"),
semconv.HTTPRouteKey.String("/users/{id}"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "DeleteUser",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
2022-08-31 06:18:14 +00:00
defer span.End()
2022-08-31 07:49:08 +00:00
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "DeleteUser",
ID: "deleteUser",
}
)
params, err := decodeDeleteUserParams(args, r)
2022-08-31 06:18:14 +00:00
if err != nil {
2022-08-31 07:49:08 +00:00
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
2022-08-31 07:49:08 +00:00
var response DeleteUserRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "DeleteUser",
OperationID: "deleteUser",
Body: nil,
Params: middleware.Parameters{
{
Name: "id",
In: "path",
}: params.ID,
},
Raw: r,
}
type (
Request = struct{}
Params = DeleteUserParams
Response = DeleteUserRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackDeleteUserParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.DeleteUser(ctx, params)
return response, err
},
)
} else {
response, err = s.h.DeleteUser(ctx, params)
}
2022-08-31 06:18:14 +00:00
if err != nil {
2022-08-31 07:49:08 +00:00
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
2022-08-31 07:49:08 +00:00
if err := encodeDeleteUserResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
}
2022-08-31 07:49:08 +00:00
// handleDrawDoneRequest handles drawDone operation.
//
// Draws a card item as done.
2022-08-31 06:18:14 +00:00
//
2022-08-31 07:49:08 +00:00
// PUT /cards/{id}/d
2022-08-31 06:18:14 +00:00
func (s *Server) handleDrawDoneRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("drawDone"),
2022-08-31 07:49:08 +00:00
semconv.HTTPMethodKey.String("PUT"),
semconv.HTTPRouteKey.String("/cards/{id}/d"),
2022-08-31 06:18:14 +00:00
}
2022-08-31 07:49:08 +00:00
// Start a span for this request.
2022-08-31 06:18:14 +00:00
ctx, span := s.cfg.Tracer.Start(r.Context(), "DrawDone",
trace.WithAttributes(otelAttrs...),
2022-08-31 07:49:08 +00:00
serverSpanKind,
2022-08-31 06:18:14 +00:00
)
defer span.End()
2022-08-31 07:49:08 +00:00
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "DrawDone",
ID: "drawDone",
}
)
2022-08-31 06:18:14 +00:00
params, err := decodeDrawDoneParams(args, r)
if err != nil {
2022-08-31 07:49:08 +00:00
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
2022-08-31 07:49:08 +00:00
var response *DrawDoneNoContent
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "DrawDone",
OperationID: "drawDone",
Body: nil,
Params: middleware.Parameters{
{
Name: "id",
In: "path",
}: params.ID,
},
Raw: r,
}
type (
Request = struct{}
Params = DrawDoneParams
Response = *DrawDoneNoContent
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackDrawDoneParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
err = s.h.DrawDone(ctx, params)
return response, err
},
)
} else {
err = s.h.DrawDone(ctx, params)
}
2022-08-31 06:18:14 +00:00
if err != nil {
2022-08-31 07:49:08 +00:00
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
if err := encodeDrawDoneResponse(response, w, span); err != nil {
2022-08-31 07:49:08 +00:00
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
}
2022-08-31 07:49:08 +00:00
// handleDrawStartRequest handles drawStart operation.
2022-08-31 06:18:14 +00:00
//
2022-08-31 07:49:08 +00:00
// Draws a card item as done.
//
// PATCH /users/{id}/card/start
2022-08-31 06:18:14 +00:00
func (s *Server) handleDrawStartRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("drawStart"),
2022-08-31 07:49:08 +00:00
semconv.HTTPMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/users/{id}/card/start"),
2022-08-31 06:18:14 +00:00
}
2022-08-31 07:49:08 +00:00
// Start a span for this request.
2022-08-31 06:18:14 +00:00
ctx, span := s.cfg.Tracer.Start(r.Context(), "DrawStart",
trace.WithAttributes(otelAttrs...),
2022-08-31 07:49:08 +00:00
serverSpanKind,
2022-08-31 06:18:14 +00:00
)
defer span.End()
2022-08-31 07:49:08 +00:00
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "DrawStart",
ID: "drawStart",
}
)
2022-08-31 06:18:14 +00:00
params, err := decodeDrawStartParams(args, r)
if err != nil {
2022-08-31 07:49:08 +00:00
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
2022-08-31 07:49:08 +00:00
var response *DrawStartNoContent
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "DrawStart",
OperationID: "drawStart",
Body: nil,
Params: middleware.Parameters{
{
Name: "id",
In: "path",
}: params.ID,
},
Raw: r,
}
type (
Request = struct{}
Params = DrawStartParams
Response = *DrawStartNoContent
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackDrawStartParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
err = s.h.DrawStart(ctx, params)
return response, err
},
)
} else {
err = s.h.DrawStart(ctx, params)
}
2022-08-31 06:18:14 +00:00
if err != nil {
2022-08-31 07:49:08 +00:00
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
if err := encodeDrawStartResponse(response, w, span); err != nil {
2022-08-31 07:49:08 +00:00
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
}
2022-08-31 07:49:08 +00:00
// handleListCardRequest handles listCard operation.
2022-08-31 06:18:14 +00:00
//
2022-08-31 07:49:08 +00:00
// List Cards.
//
// GET /cards
func (s *Server) handleListCardRequest(args [0]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("listCard"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/cards"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "ListCard",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Run stopwatch.
2022-08-31 06:18:14 +00:00
startTime := time.Now()
2022-08-31 07:49:08 +00:00
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "ListCard",
ID: "listCard",
}
)
params, err := decodeListCardParams(args, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response ListCardRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "ListCard",
OperationID: "listCard",
Body: nil,
Params: middleware.Parameters{
{
Name: "page",
In: "query",
}: params.Page,
{
Name: "itemsPerPage",
In: "query",
}: params.ItemsPerPage,
},
Raw: r,
}
type (
Request = struct{}
Params = ListCardParams
Response = ListCardRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackListCardParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.ListCard(ctx, params)
return response, err
},
)
} else {
response, err = s.h.ListCard(ctx, params)
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeListCardResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
}
// handleListGroupRequest handles listGroup operation.
//
// List Groups.
//
// GET /groups
func (s *Server) handleListGroupRequest(args [0]string, w http.ResponseWriter, r *http.Request) {
2022-08-31 06:18:14 +00:00
otelAttrs := []attribute.KeyValue{
2022-08-31 07:49:08 +00:00
otelogen.OperationID("listGroup"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/groups"),
2022-08-31 06:18:14 +00:00
}
2022-08-31 07:49:08 +00:00
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "ListGroup",
2022-08-31 06:18:14 +00:00
trace.WithAttributes(otelAttrs...),
2022-08-31 07:49:08 +00:00
serverSpanKind,
2022-08-31 06:18:14 +00:00
)
2022-08-31 07:49:08 +00:00
defer span.End()
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
2022-08-31 06:18:14 +00:00
s.requests.Add(ctx, 1, otelAttrs...)
2022-08-31 07:49:08 +00:00
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "ListGroup",
ID: "listGroup",
}
)
params, err := decodeListGroupParams(args, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response ListGroupRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "ListGroup",
OperationID: "listGroup",
Body: nil,
Params: middleware.Parameters{
{
Name: "page",
In: "query",
}: params.Page,
{
Name: "itemsPerPage",
In: "query",
}: params.ItemsPerPage,
},
Raw: r,
}
type (
Request = struct{}
Params = ListGroupParams
Response = ListGroupRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackListGroupParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.ListGroup(ctx, params)
return response, err
},
)
} else {
response, err = s.h.ListGroup(ctx, params)
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeListGroupResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
}
// handleListGroupUsersRequest handles listGroupUsers operation.
//
// List attached Users.
//
// GET /groups/{id}/users
func (s *Server) handleListGroupUsersRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("listGroupUsers"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/groups/{id}/users"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "ListGroupUsers",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
2022-08-31 06:18:14 +00:00
defer span.End()
2022-08-31 07:49:08 +00:00
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "ListGroupUsers",
ID: "listGroupUsers",
}
)
params, err := decodeListGroupUsersParams(args, r)
2022-08-31 06:18:14 +00:00
if err != nil {
2022-08-31 07:49:08 +00:00
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
2022-08-31 07:49:08 +00:00
var response ListGroupUsersRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "ListGroupUsers",
OperationID: "listGroupUsers",
Body: nil,
Params: middleware.Parameters{
{
Name: "id",
In: "path",
}: params.ID,
{
Name: "page",
In: "query",
}: params.Page,
{
Name: "itemsPerPage",
In: "query",
}: params.ItemsPerPage,
},
Raw: r,
}
type (
Request = struct{}
Params = ListGroupUsersParams
Response = ListGroupUsersRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackListGroupUsersParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.ListGroupUsers(ctx, params)
return response, err
},
)
} else {
response, err = s.h.ListGroupUsers(ctx, params)
}
2022-08-31 06:18:14 +00:00
if err != nil {
2022-08-31 07:49:08 +00:00
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
2022-08-31 07:49:08 +00:00
if err := encodeListGroupUsersResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
}
2024-02-03 06:48:28 +00:00
// handleListUeRequest handles listUe operation.
2022-08-31 06:18:14 +00:00
//
2024-02-03 06:48:28 +00:00
// List Ues.
2022-08-31 07:49:08 +00:00
//
2024-02-03 06:48:28 +00:00
// GET /ues
func (s *Server) handleListUeRequest(args [0]string, w http.ResponseWriter, r *http.Request) {
2022-08-31 07:49:08 +00:00
otelAttrs := []attribute.KeyValue{
2024-02-03 06:48:28 +00:00
otelogen.OperationID("listUe"),
2022-08-31 07:49:08 +00:00
semconv.HTTPMethodKey.String("GET"),
2024-02-03 06:48:28 +00:00
semconv.HTTPRouteKey.String("/ues"),
2022-08-31 07:49:08 +00:00
}
// Start a span for this request.
2024-02-03 06:48:28 +00:00
ctx, span := s.cfg.Tracer.Start(r.Context(), "ListUe",
2022-08-31 07:49:08 +00:00
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Run stopwatch.
2022-08-31 06:18:14 +00:00
startTime := time.Now()
2022-08-31 07:49:08 +00:00
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
2024-02-03 06:48:28 +00:00
Name: "ListUe",
ID: "listUe",
2022-08-31 07:49:08 +00:00
}
)
2024-02-03 06:48:28 +00:00
params, err := decodeListUeParams(args, r)
2022-08-31 07:49:08 +00:00
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
2024-02-03 06:48:28 +00:00
var response ListUeRes
2022-08-31 07:49:08 +00:00
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
2024-02-03 06:48:28 +00:00
OperationName: "ListUe",
OperationID: "listUe",
2022-08-31 07:49:08 +00:00
Body: nil,
Params: middleware.Parameters{
{
Name: "page",
In: "query",
}: params.Page,
{
Name: "itemsPerPage",
In: "query",
}: params.ItemsPerPage,
},
Raw: r,
}
type (
Request = struct{}
2024-02-03 06:48:28 +00:00
Params = ListUeParams
Response = ListUeRes
2022-08-31 07:49:08 +00:00
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
2024-02-03 06:48:28 +00:00
unpackListUeParams,
2022-08-31 07:49:08 +00:00
func(ctx context.Context, request Request, params Params) (response Response, err error) {
2024-02-03 06:48:28 +00:00
response, err = s.h.ListUe(ctx, params)
2022-08-31 07:49:08 +00:00
return response, err
},
)
} else {
2024-02-03 06:48:28 +00:00
response, err = s.h.ListUe(ctx, params)
2022-08-31 07:49:08 +00:00
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
2024-02-03 06:48:28 +00:00
if err := encodeListUeResponse(response, w, span); err != nil {
2022-08-31 07:49:08 +00:00
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
}
2024-02-03 06:48:28 +00:00
// handleListUserRequest handles listUser operation.
2022-08-31 07:49:08 +00:00
//
2024-02-03 06:48:28 +00:00
// List Users.
2022-08-31 07:49:08 +00:00
//
2024-02-03 06:48:28 +00:00
// GET /users
func (s *Server) handleListUserRequest(args [0]string, w http.ResponseWriter, r *http.Request) {
2022-08-31 06:18:14 +00:00
otelAttrs := []attribute.KeyValue{
2024-02-03 06:48:28 +00:00
otelogen.OperationID("listUser"),
2022-08-31 07:49:08 +00:00
semconv.HTTPMethodKey.String("GET"),
2024-02-03 06:48:28 +00:00
semconv.HTTPRouteKey.String("/users"),
2022-08-31 06:18:14 +00:00
}
2022-08-31 07:49:08 +00:00
// Start a span for this request.
2024-02-03 06:48:28 +00:00
ctx, span := s.cfg.Tracer.Start(r.Context(), "ListUser",
2022-08-31 06:18:14 +00:00
trace.WithAttributes(otelAttrs...),
2022-08-31 07:49:08 +00:00
serverSpanKind,
2022-08-31 06:18:14 +00:00
)
2022-08-31 07:49:08 +00:00
defer span.End()
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
2022-08-31 06:18:14 +00:00
s.requests.Add(ctx, 1, otelAttrs...)
2022-08-31 07:49:08 +00:00
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
2024-02-03 06:48:28 +00:00
Name: "ListUser",
ID: "listUser",
2022-08-31 07:49:08 +00:00
}
)
2024-02-03 06:48:28 +00:00
params, err := decodeListUserParams(args, r)
2022-08-31 07:49:08 +00:00
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
2024-02-03 06:48:28 +00:00
var response ListUserRes
2022-08-31 07:49:08 +00:00
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
2024-02-03 06:48:28 +00:00
OperationName: "ListUser",
OperationID: "listUser",
2022-08-31 07:49:08 +00:00
Body: nil,
Params: middleware.Parameters{
{
Name: "page",
In: "query",
}: params.Page,
{
Name: "itemsPerPage",
In: "query",
}: params.ItemsPerPage,
},
Raw: r,
}
type (
Request = struct{}
2024-02-03 06:48:28 +00:00
Params = ListUserParams
Response = ListUserRes
2022-08-31 07:49:08 +00:00
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
2024-02-03 06:48:28 +00:00
unpackListUserParams,
2022-08-31 07:49:08 +00:00
func(ctx context.Context, request Request, params Params) (response Response, err error) {
2024-02-03 06:48:28 +00:00
response, err = s.h.ListUser(ctx, params)
2022-08-31 07:49:08 +00:00
return response, err
},
)
} else {
2024-02-03 06:48:28 +00:00
response, err = s.h.ListUser(ctx, params)
2022-08-31 07:49:08 +00:00
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
2024-02-03 06:48:28 +00:00
if err := encodeListUserResponse(response, w, span); err != nil {
2022-08-31 07:49:08 +00:00
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
}
2024-02-03 06:48:28 +00:00
// handleListUserCardRequest handles listUserCard operation.
2022-08-31 07:49:08 +00:00
//
2024-02-03 06:48:28 +00:00
// List attached Cards.
2022-08-31 07:49:08 +00:00
//
2024-02-03 06:48:28 +00:00
// GET /users/{id}/card
func (s *Server) handleListUserCardRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
2022-08-31 07:49:08 +00:00
otelAttrs := []attribute.KeyValue{
2024-02-03 06:48:28 +00:00
otelogen.OperationID("listUserCard"),
2022-08-31 07:49:08 +00:00
semconv.HTTPMethodKey.String("GET"),
2024-02-03 06:48:28 +00:00
semconv.HTTPRouteKey.String("/users/{id}/card"),
2022-08-31 07:49:08 +00:00
}
// Start a span for this request.
2024-02-03 06:48:28 +00:00
ctx, span := s.cfg.Tracer.Start(r.Context(), "ListUserCard",
2022-08-31 07:49:08 +00:00
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
2022-08-31 06:18:14 +00:00
defer span.End()
2022-08-31 07:49:08 +00:00
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
2024-02-03 06:48:28 +00:00
Name: "ListUserCard",
ID: "listUserCard",
2022-08-31 07:49:08 +00:00
}
)
2024-02-03 06:48:28 +00:00
params, err := decodeListUserCardParams(args, r)
2022-08-31 06:18:14 +00:00
if err != nil {
2022-08-31 07:49:08 +00:00
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
2024-02-03 06:48:28 +00:00
var response ListUserCardRes
2022-08-31 07:49:08 +00:00
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
2024-02-03 06:48:28 +00:00
OperationName: "ListUserCard",
OperationID: "listUserCard",
2022-08-31 07:49:08 +00:00
Body: nil,
Params: middleware.Parameters{
{
Name: "id",
In: "path",
}: params.ID,
2024-02-03 06:48:28 +00:00
{
Name: "page",
In: "query",
}: params.Page,
{
Name: "itemsPerPage",
In: "query",
}: params.ItemsPerPage,
},
Raw: r,
}
type (
Request = struct{}
Params = ListUserCardParams
Response = ListUserCardRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackListUserCardParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.ListUserCard(ctx, params)
return response, err
},
)
} else {
response, err = s.h.ListUserCard(ctx, params)
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeListUserCardResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
}
// handleListUserUeRequest handles listUserUe operation.
//
// List attached Ues.
//
// GET /users/{id}/ue
func (s *Server) handleListUserUeRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("listUserUe"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/users/{id}/ue"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "ListUserUe",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "ListUserUe",
ID: "listUserUe",
}
)
params, err := decodeListUserUeParams(args, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response ListUserUeRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "ListUserUe",
OperationID: "listUserUe",
Body: nil,
Params: middleware.Parameters{
{
Name: "id",
In: "path",
}: params.ID,
{
Name: "page",
In: "query",
}: params.Page,
{
Name: "itemsPerPage",
In: "query",
}: params.ItemsPerPage,
},
Raw: r,
}
type (
Request = struct{}
Params = ListUserUeParams
Response = ListUserUeRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackListUserUeParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.ListUserUe(ctx, params)
return response, err
},
)
} else {
response, err = s.h.ListUserUe(ctx, params)
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeListUserUeResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
}
// handleReadCardRequest handles readCard operation.
//
// Finds the Card with the requested ID and returns it.
//
// GET /cards/{id}
func (s *Server) handleReadCardRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("readCard"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/cards/{id}"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "ReadCard",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "ReadCard",
ID: "readCard",
}
)
params, err := decodeReadCardParams(args, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response ReadCardRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "ReadCard",
OperationID: "readCard",
Body: nil,
Params: middleware.Parameters{
{
Name: "id",
In: "path",
}: params.ID,
},
Raw: r,
2022-08-31 07:49:08 +00:00
}
type (
Request = struct{}
Params = ReadCardParams
Response = ReadCardRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackReadCardParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.ReadCard(ctx, params)
return response, err
},
)
} else {
response, err = s.h.ReadCard(ctx, params)
}
2022-08-31 06:18:14 +00:00
if err != nil {
2022-08-31 07:49:08 +00:00
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
2022-08-31 07:49:08 +00:00
if err := encodeReadCardResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
}
2022-08-31 07:49:08 +00:00
// handleReadCardOwnerRequest handles readCardOwner operation.
2022-08-31 06:18:14 +00:00
//
2022-08-31 07:49:08 +00:00
// Find the attached User of the Card with the given ID.
//
// GET /cards/{id}/owner
func (s *Server) handleReadCardOwnerRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("readCardOwner"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/cards/{id}/owner"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "ReadCardOwner",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Run stopwatch.
2022-08-31 06:18:14 +00:00
startTime := time.Now()
2022-08-31 07:49:08 +00:00
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "ReadCardOwner",
ID: "readCardOwner",
}
)
params, err := decodeReadCardOwnerParams(args, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response ReadCardOwnerRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "ReadCardOwner",
OperationID: "readCardOwner",
Body: nil,
Params: middleware.Parameters{
{
Name: "id",
In: "path",
}: params.ID,
},
Raw: r,
}
type (
Request = struct{}
Params = ReadCardOwnerParams
Response = ReadCardOwnerRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackReadCardOwnerParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.ReadCardOwner(ctx, params)
return response, err
},
)
} else {
response, err = s.h.ReadCardOwner(ctx, params)
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeReadCardOwnerResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
}
// handleReadGroupRequest handles readGroup operation.
//
// Finds the Group with the requested ID and returns it.
//
// GET /groups/{id}
func (s *Server) handleReadGroupRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
2022-08-31 06:18:14 +00:00
otelAttrs := []attribute.KeyValue{
2022-08-31 07:49:08 +00:00
otelogen.OperationID("readGroup"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/groups/{id}"),
2022-08-31 06:18:14 +00:00
}
2022-08-31 07:49:08 +00:00
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "ReadGroup",
2022-08-31 06:18:14 +00:00
trace.WithAttributes(otelAttrs...),
2022-08-31 07:49:08 +00:00
serverSpanKind,
2022-08-31 06:18:14 +00:00
)
2022-08-31 07:49:08 +00:00
defer span.End()
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
2022-08-31 06:18:14 +00:00
s.requests.Add(ctx, 1, otelAttrs...)
2022-08-31 07:49:08 +00:00
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "ReadGroup",
ID: "readGroup",
}
)
params, err := decodeReadGroupParams(args, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response ReadGroupRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "ReadGroup",
OperationID: "readGroup",
Body: nil,
Params: middleware.Parameters{
{
Name: "id",
In: "path",
}: params.ID,
},
Raw: r,
}
type (
Request = struct{}
Params = ReadGroupParams
Response = ReadGroupRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackReadGroupParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.ReadGroup(ctx, params)
return response, err
},
)
} else {
response, err = s.h.ReadGroup(ctx, params)
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeReadGroupResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
}
2024-02-03 06:48:28 +00:00
// handleReadUeRequest handles readUe operation.
//
// Finds the Ue with the requested ID and returns it.
//
// GET /ues/{id}
func (s *Server) handleReadUeRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("readUe"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/ues/{id}"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "ReadUe",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "ReadUe",
ID: "readUe",
}
)
params, err := decodeReadUeParams(args, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response ReadUeRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "ReadUe",
OperationID: "readUe",
Body: nil,
Params: middleware.Parameters{
{
Name: "id",
In: "path",
}: params.ID,
},
Raw: r,
}
type (
Request = struct{}
Params = ReadUeParams
Response = ReadUeRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackReadUeParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.ReadUe(ctx, params)
return response, err
},
)
} else {
response, err = s.h.ReadUe(ctx, params)
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeReadUeResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
}
// handleReadUeOwnerRequest handles readUeOwner operation.
//
// Find the attached User of the Ue with the given ID.
//
// GET /ues/{id}/owner
func (s *Server) handleReadUeOwnerRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("readUeOwner"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/ues/{id}/owner"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "ReadUeOwner",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "ReadUeOwner",
ID: "readUeOwner",
}
)
params, err := decodeReadUeOwnerParams(args, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response ReadUeOwnerRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "ReadUeOwner",
OperationID: "readUeOwner",
Body: nil,
Params: middleware.Parameters{
{
Name: "id",
In: "path",
}: params.ID,
},
Raw: r,
}
type (
Request = struct{}
Params = ReadUeOwnerParams
Response = ReadUeOwnerRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackReadUeOwnerParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.ReadUeOwner(ctx, params)
return response, err
},
)
} else {
response, err = s.h.ReadUeOwner(ctx, params)
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeReadUeOwnerResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
}
2022-08-31 07:49:08 +00:00
// handleReadUserRequest handles readUser operation.
//
// Finds the User with the requested ID and returns it.
//
// GET /users/{id}
func (s *Server) handleReadUserRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("readUser"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/users/{id}"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "ReadUser",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "ReadUser",
ID: "readUser",
}
)
params, err := decodeReadUserParams(args, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response ReadUserRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "ReadUser",
OperationID: "readUser",
Body: nil,
Params: middleware.Parameters{
{
Name: "id",
In: "path",
}: params.ID,
},
Raw: r,
}
type (
Request = struct{}
Params = ReadUserParams
Response = ReadUserRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackReadUserParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.ReadUser(ctx, params)
return response, err
},
)
} else {
response, err = s.h.ReadUser(ctx, params)
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeReadUserResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
}
// handleUpdateCardRequest handles updateCard operation.
//
// Updates a Card and persists changes to storage.
//
// PATCH /cards/{id}
func (s *Server) handleUpdateCardRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("updateCard"),
semconv.HTTPMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/cards/{id}"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "UpdateCard",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
2022-08-31 06:18:14 +00:00
defer span.End()
2022-08-31 07:49:08 +00:00
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "UpdateCard",
ID: "updateCard",
}
)
params, err := decodeUpdateCardParams(args, r)
2022-08-31 06:18:14 +00:00
if err != nil {
2022-08-31 07:49:08 +00:00
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
2022-08-31 07:49:08 +00:00
request, close, err := s.decodeUpdateCardRequest(r)
2022-08-31 06:18:14 +00:00
if err != nil {
2022-08-31 07:49:08 +00:00
err = &ogenerrors.DecodeRequestError{
OperationContext: opErrContext,
Err: err,
}
recordError("DecodeRequest", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
2022-08-31 07:49:08 +00:00
defer func() {
if err := close(); err != nil {
recordError("CloseRequest", err)
}
}()
2022-08-31 06:18:14 +00:00
2022-08-31 07:49:08 +00:00
var response UpdateCardRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "UpdateCard",
OperationID: "updateCard",
Body: request,
Params: middleware.Parameters{
{
Name: "id",
In: "path",
}: params.ID,
},
Raw: r,
}
type (
Request = *UpdateCardReq
Params = UpdateCardParams
Response = UpdateCardRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackUpdateCardParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.UpdateCard(ctx, request, params)
return response, err
},
)
} else {
response, err = s.h.UpdateCard(ctx, request, params)
}
2022-08-31 06:18:14 +00:00
if err != nil {
2022-08-31 07:49:08 +00:00
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
2022-08-31 07:49:08 +00:00
if err := encodeUpdateCardResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
2022-08-31 06:18:14 +00:00
return
}
}
2022-08-31 07:49:08 +00:00
// handleUpdateGroupRequest handles updateGroup operation.
//
// Updates a Group and persists changes to storage.
//
// PATCH /groups/{id}
func (s *Server) handleUpdateGroupRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("updateGroup"),
semconv.HTTPMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/groups/{id}"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "UpdateGroup",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "UpdateGroup",
ID: "updateGroup",
}
)
params, err := decodeUpdateGroupParams(args, 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.decodeUpdateGroupRequest(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 UpdateGroupRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "UpdateGroup",
OperationID: "updateGroup",
Body: request,
Params: middleware.Parameters{
{
Name: "id",
In: "path",
}: params.ID,
},
Raw: r,
}
type (
Request = *UpdateGroupReq
Params = UpdateGroupParams
Response = UpdateGroupRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackUpdateGroupParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.UpdateGroup(ctx, request, params)
return response, err
},
)
} else {
response, err = s.h.UpdateGroup(ctx, request, params)
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeUpdateGroupResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
2022-08-31 06:18:14 +00:00
}
2024-02-03 06:48:28 +00:00
// handleUpdateUeRequest handles updateUe operation.
//
// Updates a Ue and persists changes to storage.
//
// PATCH /ues/{id}
func (s *Server) handleUpdateUeRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("updateUe"),
semconv.HTTPMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/ues/{id}"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "UpdateUe",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "UpdateUe",
ID: "updateUe",
}
)
params, err := decodeUpdateUeParams(args, 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.decodeUpdateUeRequest(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 UpdateUeRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "UpdateUe",
OperationID: "updateUe",
Body: request,
Params: middleware.Parameters{
{
Name: "id",
In: "path",
}: params.ID,
},
Raw: r,
}
type (
Request = *UpdateUeReq
Params = UpdateUeParams
Response = UpdateUeRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackUpdateUeParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.UpdateUe(ctx, request, params)
return response, err
},
)
} else {
response, err = s.h.UpdateUe(ctx, request, params)
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeUpdateUeResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
}
2022-08-31 07:49:08 +00:00
// handleUpdateUserRequest handles updateUser operation.
//
// Updates a User and persists changes to storage.
//
// PATCH /users/{id}
func (s *Server) handleUpdateUserRequest(args [1]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("updateUser"),
semconv.HTTPMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/users/{id}"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "UpdateUser",
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...)
}()
// Increment request counter.
s.requests.Add(ctx, 1, otelAttrs...)
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, otelAttrs...)
}
err error
opErrContext = ogenerrors.OperationContext{
Name: "UpdateUser",
ID: "updateUser",
}
)
params, err := decodeUpdateUserParams(args, 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.decodeUpdateUserRequest(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 UpdateUserRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "UpdateUser",
OperationID: "updateUser",
Body: request,
Params: middleware.Parameters{
{
Name: "id",
In: "path",
}: params.ID,
},
Raw: r,
}
type (
Request = *UpdateUserReq
Params = UpdateUserParams
Response = UpdateUserRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackUpdateUserParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.UpdateUser(ctx, request, params)
return response, err
},
)
} else {
response, err = s.h.UpdateUser(ctx, request, params)
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeUpdateUserResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
2022-08-31 06:18:14 +00:00
}
}