510 lines
12 KiB
Go
510 lines
12 KiB
Go
// Code generated by ogen, DO NOT EDIT.
|
|
|
|
package api
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/go-faster/errors"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/codes"
|
|
"go.opentelemetry.io/otel/metric"
|
|
semconv "go.opentelemetry.io/otel/semconv/v1.19.0"
|
|
"go.opentelemetry.io/otel/trace"
|
|
|
|
ht "github.com/ogen-go/ogen/http"
|
|
"github.com/ogen-go/ogen/middleware"
|
|
"github.com/ogen-go/ogen/ogenerrors"
|
|
"github.com/ogen-go/ogen/otelogen"
|
|
)
|
|
|
|
// handleGetUserRequest handles getUser operation.
|
|
//
|
|
// Retrieve user with ID.
|
|
//
|
|
// GET /users/{UserID}
|
|
func (s *Server) handleGetUserRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
|
otelAttrs := []attribute.KeyValue{
|
|
otelogen.OperationID("getUser"),
|
|
semconv.HTTPMethodKey.String("GET"),
|
|
semconv.HTTPRouteKey.String("/users/{UserID}"),
|
|
}
|
|
|
|
// Start a span for this request.
|
|
ctx, span := s.cfg.Tracer.Start(r.Context(), "GetUser",
|
|
trace.WithAttributes(otelAttrs...),
|
|
serverSpanKind,
|
|
)
|
|
defer span.End()
|
|
|
|
// Run stopwatch.
|
|
startTime := time.Now()
|
|
defer func() {
|
|
elapsedDuration := time.Since(startTime)
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...))
|
|
}()
|
|
|
|
// Increment request counter.
|
|
s.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
var (
|
|
recordError = func(stage string, err error) {
|
|
span.RecordError(err)
|
|
span.SetStatus(codes.Error, stage)
|
|
s.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
}
|
|
err error
|
|
opErrContext = ogenerrors.OperationContext{
|
|
Name: "GetUser",
|
|
ID: "getUser",
|
|
}
|
|
)
|
|
params, err := decodeGetUserParams(args, argsEscaped, r)
|
|
if err != nil {
|
|
err = &ogenerrors.DecodeParamsError{
|
|
OperationContext: opErrContext,
|
|
Err: err,
|
|
}
|
|
recordError("DecodeParams", err)
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
return
|
|
}
|
|
|
|
var response *User
|
|
if m := s.cfg.Middleware; m != nil {
|
|
mreq := middleware.Request{
|
|
Context: ctx,
|
|
OperationName: "GetUser",
|
|
OperationSummary: "Retrieve user with ID",
|
|
OperationID: "getUser",
|
|
Body: nil,
|
|
Params: middleware.Parameters{
|
|
{
|
|
Name: "UserID",
|
|
In: "path",
|
|
}: params.UserID,
|
|
},
|
|
Raw: r,
|
|
}
|
|
|
|
type (
|
|
Request = struct{}
|
|
Params = GetUserParams
|
|
Response = *User
|
|
)
|
|
response, err = middleware.HookMiddleware[
|
|
Request,
|
|
Params,
|
|
Response,
|
|
](
|
|
m,
|
|
mreq,
|
|
unpackGetUserParams,
|
|
func(ctx context.Context, request Request, params Params) (response Response, err error) {
|
|
response, err = s.h.GetUser(ctx, params)
|
|
return response, err
|
|
},
|
|
)
|
|
} else {
|
|
response, err = s.h.GetUser(ctx, params)
|
|
}
|
|
if err != nil {
|
|
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
|
|
if err := encodeErrorResponse(errRes, w, span); err != nil {
|
|
recordError("Internal", err)
|
|
}
|
|
return
|
|
}
|
|
if errors.Is(err, ht.ErrNotImplemented) {
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
return
|
|
}
|
|
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
|
|
recordError("Internal", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
if err := encodeGetUserResponse(response, w, span); err != nil {
|
|
recordError("EncodeResponse", err)
|
|
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
}
|
|
return
|
|
}
|
|
}
|
|
|
|
// handleGetUserRankRequest handles getUserRank operation.
|
|
//
|
|
// Retrieve rank of user.
|
|
//
|
|
// GET /users/{UserID}/rank
|
|
func (s *Server) handleGetUserRankRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
|
otelAttrs := []attribute.KeyValue{
|
|
otelogen.OperationID("getUserRank"),
|
|
semconv.HTTPMethodKey.String("GET"),
|
|
semconv.HTTPRouteKey.String("/users/{UserID}/rank"),
|
|
}
|
|
|
|
// Start a span for this request.
|
|
ctx, span := s.cfg.Tracer.Start(r.Context(), "GetUserRank",
|
|
trace.WithAttributes(otelAttrs...),
|
|
serverSpanKind,
|
|
)
|
|
defer span.End()
|
|
|
|
// Run stopwatch.
|
|
startTime := time.Now()
|
|
defer func() {
|
|
elapsedDuration := time.Since(startTime)
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...))
|
|
}()
|
|
|
|
// Increment request counter.
|
|
s.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
var (
|
|
recordError = func(stage string, err error) {
|
|
span.RecordError(err)
|
|
span.SetStatus(codes.Error, stage)
|
|
s.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
}
|
|
err error
|
|
opErrContext = ogenerrors.OperationContext{
|
|
Name: "GetUserRank",
|
|
ID: "getUserRank",
|
|
}
|
|
)
|
|
params, err := decodeGetUserRankParams(args, argsEscaped, r)
|
|
if err != nil {
|
|
err = &ogenerrors.DecodeParamsError{
|
|
OperationContext: opErrContext,
|
|
Err: err,
|
|
}
|
|
recordError("DecodeParams", err)
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
return
|
|
}
|
|
|
|
var response *Rank
|
|
if m := s.cfg.Middleware; m != nil {
|
|
mreq := middleware.Request{
|
|
Context: ctx,
|
|
OperationName: "GetUserRank",
|
|
OperationSummary: "Retrieve rank of user",
|
|
OperationID: "getUserRank",
|
|
Body: nil,
|
|
Params: middleware.Parameters{
|
|
{
|
|
Name: "UserID",
|
|
In: "path",
|
|
}: params.UserID,
|
|
{
|
|
Name: "StyleID",
|
|
In: "query",
|
|
}: params.StyleID,
|
|
{
|
|
Name: "GameID",
|
|
In: "query",
|
|
}: params.GameID,
|
|
{
|
|
Name: "ModeID",
|
|
In: "query",
|
|
}: params.ModeID,
|
|
},
|
|
Raw: r,
|
|
}
|
|
|
|
type (
|
|
Request = struct{}
|
|
Params = GetUserRankParams
|
|
Response = *Rank
|
|
)
|
|
response, err = middleware.HookMiddleware[
|
|
Request,
|
|
Params,
|
|
Response,
|
|
](
|
|
m,
|
|
mreq,
|
|
unpackGetUserRankParams,
|
|
func(ctx context.Context, request Request, params Params) (response Response, err error) {
|
|
response, err = s.h.GetUserRank(ctx, params)
|
|
return response, err
|
|
},
|
|
)
|
|
} else {
|
|
response, err = s.h.GetUserRank(ctx, params)
|
|
}
|
|
if err != nil {
|
|
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
|
|
if err := encodeErrorResponse(errRes, w, span); err != nil {
|
|
recordError("Internal", err)
|
|
}
|
|
return
|
|
}
|
|
if errors.Is(err, ht.ErrNotImplemented) {
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
return
|
|
}
|
|
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
|
|
recordError("Internal", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
if err := encodeGetUserRankResponse(response, w, span); err != nil {
|
|
recordError("EncodeResponse", err)
|
|
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
}
|
|
return
|
|
}
|
|
}
|
|
|
|
// handleListRanksRequest handles listRanks operation.
|
|
//
|
|
// Get list of ranks.
|
|
//
|
|
// GET /ranks
|
|
func (s *Server) handleListRanksRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
|
otelAttrs := []attribute.KeyValue{
|
|
otelogen.OperationID("listRanks"),
|
|
semconv.HTTPMethodKey.String("GET"),
|
|
semconv.HTTPRouteKey.String("/ranks"),
|
|
}
|
|
|
|
// Start a span for this request.
|
|
ctx, span := s.cfg.Tracer.Start(r.Context(), "ListRanks",
|
|
trace.WithAttributes(otelAttrs...),
|
|
serverSpanKind,
|
|
)
|
|
defer span.End()
|
|
|
|
// Run stopwatch.
|
|
startTime := time.Now()
|
|
defer func() {
|
|
elapsedDuration := time.Since(startTime)
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...))
|
|
}()
|
|
|
|
// Increment request counter.
|
|
s.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
var (
|
|
recordError = func(stage string, err error) {
|
|
span.RecordError(err)
|
|
span.SetStatus(codes.Error, stage)
|
|
s.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
}
|
|
err error
|
|
opErrContext = ogenerrors.OperationContext{
|
|
Name: "ListRanks",
|
|
ID: "listRanks",
|
|
}
|
|
)
|
|
params, err := decodeListRanksParams(args, argsEscaped, r)
|
|
if err != nil {
|
|
err = &ogenerrors.DecodeParamsError{
|
|
OperationContext: opErrContext,
|
|
Err: err,
|
|
}
|
|
recordError("DecodeParams", err)
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
return
|
|
}
|
|
|
|
var response []Rank
|
|
if m := s.cfg.Middleware; m != nil {
|
|
mreq := middleware.Request{
|
|
Context: ctx,
|
|
OperationName: "ListRanks",
|
|
OperationSummary: "Get list of ranks",
|
|
OperationID: "listRanks",
|
|
Body: nil,
|
|
Params: middleware.Parameters{
|
|
{
|
|
Name: "page",
|
|
In: "query",
|
|
}: params.Page,
|
|
{
|
|
Name: "filter",
|
|
In: "query",
|
|
}: params.Filter,
|
|
},
|
|
Raw: r,
|
|
}
|
|
|
|
type (
|
|
Request = struct{}
|
|
Params = ListRanksParams
|
|
Response = []Rank
|
|
)
|
|
response, err = middleware.HookMiddleware[
|
|
Request,
|
|
Params,
|
|
Response,
|
|
](
|
|
m,
|
|
mreq,
|
|
unpackListRanksParams,
|
|
func(ctx context.Context, request Request, params Params) (response Response, err error) {
|
|
response, err = s.h.ListRanks(ctx, params)
|
|
return response, err
|
|
},
|
|
)
|
|
} else {
|
|
response, err = s.h.ListRanks(ctx, params)
|
|
}
|
|
if err != nil {
|
|
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
|
|
if err := encodeErrorResponse(errRes, w, span); err != nil {
|
|
recordError("Internal", err)
|
|
}
|
|
return
|
|
}
|
|
if errors.Is(err, ht.ErrNotImplemented) {
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
return
|
|
}
|
|
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
|
|
recordError("Internal", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
if err := encodeListRanksResponse(response, w, span); err != nil {
|
|
recordError("EncodeResponse", err)
|
|
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
}
|
|
return
|
|
}
|
|
}
|
|
|
|
// handleListTimesRequest handles listTimes operation.
|
|
//
|
|
// Get list of times.
|
|
//
|
|
// GET /times
|
|
func (s *Server) handleListTimesRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
|
otelAttrs := []attribute.KeyValue{
|
|
otelogen.OperationID("listTimes"),
|
|
semconv.HTTPMethodKey.String("GET"),
|
|
semconv.HTTPRouteKey.String("/times"),
|
|
}
|
|
|
|
// Start a span for this request.
|
|
ctx, span := s.cfg.Tracer.Start(r.Context(), "ListTimes",
|
|
trace.WithAttributes(otelAttrs...),
|
|
serverSpanKind,
|
|
)
|
|
defer span.End()
|
|
|
|
// Run stopwatch.
|
|
startTime := time.Now()
|
|
defer func() {
|
|
elapsedDuration := time.Since(startTime)
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...))
|
|
}()
|
|
|
|
// Increment request counter.
|
|
s.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
var (
|
|
recordError = func(stage string, err error) {
|
|
span.RecordError(err)
|
|
span.SetStatus(codes.Error, stage)
|
|
s.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
}
|
|
err error
|
|
opErrContext = ogenerrors.OperationContext{
|
|
Name: "ListTimes",
|
|
ID: "listTimes",
|
|
}
|
|
)
|
|
params, err := decodeListTimesParams(args, argsEscaped, r)
|
|
if err != nil {
|
|
err = &ogenerrors.DecodeParamsError{
|
|
OperationContext: opErrContext,
|
|
Err: err,
|
|
}
|
|
recordError("DecodeParams", err)
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
return
|
|
}
|
|
|
|
var response []Time
|
|
if m := s.cfg.Middleware; m != nil {
|
|
mreq := middleware.Request{
|
|
Context: ctx,
|
|
OperationName: "ListTimes",
|
|
OperationSummary: "Get list of times",
|
|
OperationID: "listTimes",
|
|
Body: nil,
|
|
Params: middleware.Parameters{
|
|
{
|
|
Name: "page",
|
|
In: "query",
|
|
}: params.Page,
|
|
{
|
|
Name: "filter",
|
|
In: "query",
|
|
}: params.Filter,
|
|
},
|
|
Raw: r,
|
|
}
|
|
|
|
type (
|
|
Request = struct{}
|
|
Params = ListTimesParams
|
|
Response = []Time
|
|
)
|
|
response, err = middleware.HookMiddleware[
|
|
Request,
|
|
Params,
|
|
Response,
|
|
](
|
|
m,
|
|
mreq,
|
|
unpackListTimesParams,
|
|
func(ctx context.Context, request Request, params Params) (response Response, err error) {
|
|
response, err = s.h.ListTimes(ctx, params)
|
|
return response, err
|
|
},
|
|
)
|
|
} else {
|
|
response, err = s.h.ListTimes(ctx, params)
|
|
}
|
|
if err != nil {
|
|
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
|
|
if err := encodeErrorResponse(errRes, w, span); err != nil {
|
|
recordError("Internal", err)
|
|
}
|
|
return
|
|
}
|
|
if errors.Is(err, ht.ErrNotImplemented) {
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
return
|
|
}
|
|
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
|
|
recordError("Internal", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
if err := encodeListTimesResponse(response, w, span); err != nil {
|
|
recordError("EncodeResponse", err)
|
|
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
}
|
|
return
|
|
}
|
|
}
|