1
0
api/ent/ogent/oas_handlers_gen.go

2132 lines
49 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
}
}
// 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
}
}
// 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
}
}
2022-08-31 07:49:08 +00:00
// handleListUserRequest handles listUser operation.
2022-08-31 06:18:14 +00:00
//
2022-08-31 07:49:08 +00:00
// List Users.
//
// GET /users
func (s *Server) handleListUserRequest(args [0]string, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("listUser"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/users"),
}
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), "ListUser",
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: "ListUser",
ID: "listUser",
}
)
params, err := decodeListUserParams(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 ListUserRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "ListUser",
OperationID: "listUser",
Body: nil,
Params: middleware.Parameters{
{
Name: "page",
In: "query",
}: params.Page,
{
Name: "itemsPerPage",
In: "query",
}: params.ItemsPerPage,
},
Raw: r,
}
type (
Request = struct{}
Params = ListUserParams
Response = ListUserRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackListUserParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.ListUser(ctx, params)
return response, err
},
)
} else {
response, err = s.h.ListUser(ctx, params)
}
if err != nil {
recordError("Internal", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeListUserResponse(response, w, span); err != nil {
recordError("EncodeResponse", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
}
// handleListUserCardRequest handles listUserCard operation.
//
// List attached Cards.
//
// GET /users/{id}/card
func (s *Server) handleListUserCardRequest(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("listUserCard"),
semconv.HTTPMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/users/{id}/card"),
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(), "ListUserCard",
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: "ListUserCard",
ID: "listUserCard",
}
)
params, err := decodeListUserCardParams(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 ListUserCardRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: "ListUserCard",
OperationID: "listUserCard",
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 = 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
}
}
// 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,
)
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: "ReadCard",
ID: "readCard",
}
)
params, err := decodeReadCardParams(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 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,
}
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
}
}
// 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
}
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
}
}