maps-service/pkg/api/oas_client_gen.go

710 lines
19 KiB
Go
Raw Normal View History

2024-11-26 01:22:45 +00:00
// Code generated by ogen, DO NOT EDIT.
package api
import (
"context"
"net/url"
"strings"
"time"
"github.com/go-faster/errors"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/metric"
2024-11-26 20:39:10 +00:00
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
2024-11-26 01:22:45 +00:00
"go.opentelemetry.io/otel/trace"
"github.com/ogen-go/ogen/conv"
ht "github.com/ogen-go/ogen/http"
"github.com/ogen-go/ogen/otelogen"
"github.com/ogen-go/ogen/uri"
)
// Invoker invokes operations described by OpenAPI v3 specification.
type Invoker interface {
2024-11-26 20:39:10 +00:00
// CreateSubmission invokes createSubmission operation.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// Create new submission.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// POST /submissions
2024-11-27 23:38:17 +00:00
CreateSubmission(ctx context.Context, request OptSubmissionCreate) (*ID, error)
2024-11-26 20:39:10 +00:00
// GetSubmission invokes getSubmission operation.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// Retrieve map with ID.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// GET /submissions/{SubmissionID}
GetSubmission(ctx context.Context, params GetSubmissionParams) (*Submission, error)
// ListSubmissions invokes listSubmissions operation.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// Get list of submissions.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// GET /submissions
ListSubmissions(ctx context.Context, params ListSubmissionsParams) ([]Submission, error)
// PatchSubmissionCompleted invokes patchSubmissionCompleted operation.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// Retrieve map with ID.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// PATCH /submissions/{SubmissionID}/completed
PatchSubmissionCompleted(ctx context.Context, params PatchSubmissionCompletedParams) error
// PatchSubmissionModel invokes patchSubmissionModel operation.
//
// Update model following role restrictions.
//
// PATCH /submissions/{SubmissionID}/model
PatchSubmissionModel(ctx context.Context, params PatchSubmissionModelParams) error
// PatchSubmissionStatus invokes patchSubmissionStatus operation.
//
// Update status following role restrictions.
//
// PATCH /submissions/{SubmissionID}/status
PatchSubmissionStatus(ctx context.Context, params PatchSubmissionStatusParams) error
2024-11-26 01:22:45 +00:00
}
// Client implements OAS client.
type Client struct {
serverURL *url.URL
baseClient
}
type errorHandler interface {
NewError(ctx context.Context, err error) *ErrorStatusCode
}
var _ Handler = struct {
errorHandler
*Client
}{}
func trimTrailingSlashes(u *url.URL) {
u.Path = strings.TrimRight(u.Path, "/")
u.RawPath = strings.TrimRight(u.RawPath, "/")
}
// NewClient initializes new Client defined by OAS.
func NewClient(serverURL string, opts ...ClientOption) (*Client, error) {
u, err := url.Parse(serverURL)
if err != nil {
return nil, err
}
trimTrailingSlashes(u)
c, err := newClientConfig(opts...).baseClient()
if err != nil {
return nil, err
}
return &Client{
serverURL: u,
baseClient: c,
}, nil
}
type serverURLKey struct{}
// WithServerURL sets context key to override server URL.
func WithServerURL(ctx context.Context, u *url.URL) context.Context {
return context.WithValue(ctx, serverURLKey{}, u)
}
func (c *Client) requestURL(ctx context.Context) *url.URL {
u, ok := ctx.Value(serverURLKey{}).(*url.URL)
if !ok {
return c.serverURL
}
return u
}
2024-11-26 20:39:10 +00:00
// CreateSubmission invokes createSubmission operation.
//
// Create new submission.
//
// POST /submissions
2024-11-27 23:38:17 +00:00
func (c *Client) CreateSubmission(ctx context.Context, request OptSubmissionCreate) (*ID, error) {
res, err := c.sendCreateSubmission(ctx, request)
2024-11-26 20:39:10 +00:00
return res, err
}
2024-11-27 23:38:17 +00:00
func (c *Client) sendCreateSubmission(ctx context.Context, request OptSubmissionCreate) (res *ID, err error) {
2024-11-26 20:39:10 +00:00
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("createSubmission"),
semconv.HTTPRequestMethodKey.String("POST"),
semconv.HTTPRouteKey.String("/submissions"),
}
// Run stopwatch.
startTime := time.Now()
defer func() {
// Use floating point division here for higher precision (instead of Millisecond method).
elapsedDuration := time.Since(startTime)
c.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...))
}()
// Increment request counter.
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
// Start a span for this request.
ctx, span := c.cfg.Tracer.Start(ctx, "CreateSubmission",
trace.WithAttributes(otelAttrs...),
clientSpanKind,
)
// Track stage for error reporting.
var stage string
defer func() {
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
}
span.End()
}()
stage = "BuildURL"
u := uri.Clone(c.requestURL(ctx))
var pathParts [1]string
pathParts[0] = "/submissions"
uri.AddPathParts(u, pathParts[:]...)
stage = "EncodeRequest"
r, err := ht.NewRequest(ctx, "POST", u)
if err != nil {
return res, errors.Wrap(err, "create request")
}
2024-11-27 23:38:17 +00:00
if err := encodeCreateSubmissionRequest(request, r); err != nil {
return res, errors.Wrap(err, "encode request")
}
2024-11-26 20:39:10 +00:00
stage = "SendRequest"
resp, err := c.cfg.Client.Do(r)
if err != nil {
return res, errors.Wrap(err, "do request")
}
defer resp.Body.Close()
stage = "DecodeResponse"
result, err := decodeCreateSubmissionResponse(resp)
if err != nil {
return res, errors.Wrap(err, "decode response")
}
return result, nil
}
// GetSubmission invokes getSubmission operation.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// Retrieve map with ID.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// GET /submissions/{SubmissionID}
func (c *Client) GetSubmission(ctx context.Context, params GetSubmissionParams) (*Submission, error) {
res, err := c.sendGetSubmission(ctx, params)
2024-11-26 01:22:45 +00:00
return res, err
}
2024-11-26 20:39:10 +00:00
func (c *Client) sendGetSubmission(ctx context.Context, params GetSubmissionParams) (res *Submission, err error) {
2024-11-26 01:22:45 +00:00
otelAttrs := []attribute.KeyValue{
2024-11-26 20:39:10 +00:00
otelogen.OperationID("getSubmission"),
semconv.HTTPRequestMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}"),
2024-11-26 01:22:45 +00:00
}
// Run stopwatch.
startTime := time.Now()
defer func() {
// Use floating point division here for higher precision (instead of Millisecond method).
elapsedDuration := time.Since(startTime)
c.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...))
}()
// Increment request counter.
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
// Start a span for this request.
2024-11-26 20:39:10 +00:00
ctx, span := c.cfg.Tracer.Start(ctx, "GetSubmission",
2024-11-26 01:22:45 +00:00
trace.WithAttributes(otelAttrs...),
clientSpanKind,
)
// Track stage for error reporting.
var stage string
defer func() {
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
}
span.End()
}()
stage = "BuildURL"
u := uri.Clone(c.requestURL(ctx))
var pathParts [2]string
2024-11-26 20:39:10 +00:00
pathParts[0] = "/submissions/"
2024-11-26 01:22:45 +00:00
{
2024-11-26 20:39:10 +00:00
// Encode "SubmissionID" parameter.
2024-11-26 01:22:45 +00:00
e := uri.NewPathEncoder(uri.PathEncoderConfig{
2024-11-26 20:39:10 +00:00
Param: "SubmissionID",
2024-11-26 01:22:45 +00:00
Style: uri.PathStyleSimple,
Explode: false,
})
if err := func() error {
2024-11-26 20:39:10 +00:00
return e.EncodeValue(conv.Int64ToString(params.SubmissionID))
2024-11-26 01:22:45 +00:00
}(); err != nil {
return res, errors.Wrap(err, "encode path")
}
encoded, err := e.Result()
if err != nil {
return res, errors.Wrap(err, "encode path")
}
pathParts[1] = encoded
}
uri.AddPathParts(u, pathParts[:]...)
stage = "EncodeRequest"
r, err := ht.NewRequest(ctx, "GET", u)
if err != nil {
return res, errors.Wrap(err, "create request")
}
stage = "SendRequest"
resp, err := c.cfg.Client.Do(r)
if err != nil {
return res, errors.Wrap(err, "do request")
}
defer resp.Body.Close()
stage = "DecodeResponse"
2024-11-26 20:39:10 +00:00
result, err := decodeGetSubmissionResponse(resp)
2024-11-26 01:22:45 +00:00
if err != nil {
return res, errors.Wrap(err, "decode response")
}
return result, nil
}
2024-11-26 20:39:10 +00:00
// ListSubmissions invokes listSubmissions operation.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// Get list of submissions.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// GET /submissions
func (c *Client) ListSubmissions(ctx context.Context, params ListSubmissionsParams) ([]Submission, error) {
res, err := c.sendListSubmissions(ctx, params)
2024-11-26 01:22:45 +00:00
return res, err
}
2024-11-26 20:39:10 +00:00
func (c *Client) sendListSubmissions(ctx context.Context, params ListSubmissionsParams) (res []Submission, err error) {
2024-11-26 01:22:45 +00:00
otelAttrs := []attribute.KeyValue{
2024-11-26 20:39:10 +00:00
otelogen.OperationID("listSubmissions"),
semconv.HTTPRequestMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/submissions"),
2024-11-26 01:22:45 +00:00
}
// Run stopwatch.
startTime := time.Now()
defer func() {
// Use floating point division here for higher precision (instead of Millisecond method).
elapsedDuration := time.Since(startTime)
c.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...))
}()
// Increment request counter.
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
// Start a span for this request.
2024-11-26 20:39:10 +00:00
ctx, span := c.cfg.Tracer.Start(ctx, "ListSubmissions",
2024-11-26 01:22:45 +00:00
trace.WithAttributes(otelAttrs...),
clientSpanKind,
)
// Track stage for error reporting.
var stage string
defer func() {
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
}
span.End()
}()
stage = "BuildURL"
u := uri.Clone(c.requestURL(ctx))
2024-11-26 20:39:10 +00:00
var pathParts [1]string
pathParts[0] = "/submissions"
2024-11-26 01:22:45 +00:00
uri.AddPathParts(u, pathParts[:]...)
stage = "EncodeQueryParams"
q := uri.NewQueryEncoder()
{
2024-11-26 20:39:10 +00:00
// Encode "page" parameter.
2024-11-26 01:22:45 +00:00
cfg := uri.QueryParameterEncodingConfig{
2024-11-26 20:39:10 +00:00
Name: "page",
2024-11-26 01:22:45 +00:00
Style: uri.QueryStyleForm,
Explode: true,
}
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
2024-11-26 20:39:10 +00:00
return params.Page.EncodeURI(e)
2024-11-26 01:22:45 +00:00
}); err != nil {
return res, errors.Wrap(err, "encode query")
}
}
{
2024-11-26 20:39:10 +00:00
// Encode "filter" parameter.
2024-11-26 01:22:45 +00:00
cfg := uri.QueryParameterEncodingConfig{
2024-11-26 20:39:10 +00:00
Name: "filter",
2024-11-26 01:22:45 +00:00
Style: uri.QueryStyleForm,
Explode: true,
}
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
2024-11-26 20:39:10 +00:00
if val, ok := params.Filter.Get(); ok {
return val.EncodeURI(e)
}
return nil
2024-11-26 01:22:45 +00:00
}); err != nil {
return res, errors.Wrap(err, "encode query")
}
}
2024-11-26 20:39:10 +00:00
u.RawQuery = q.Values().Encode()
stage = "EncodeRequest"
r, err := ht.NewRequest(ctx, "GET", u)
if err != nil {
return res, errors.Wrap(err, "create request")
}
stage = "SendRequest"
resp, err := c.cfg.Client.Do(r)
if err != nil {
return res, errors.Wrap(err, "do request")
}
defer resp.Body.Close()
stage = "DecodeResponse"
result, err := decodeListSubmissionsResponse(resp)
if err != nil {
return res, errors.Wrap(err, "decode response")
}
return result, nil
}
// PatchSubmissionCompleted invokes patchSubmissionCompleted operation.
//
// Retrieve map with ID.
//
// PATCH /submissions/{SubmissionID}/completed
func (c *Client) PatchSubmissionCompleted(ctx context.Context, params PatchSubmissionCompletedParams) error {
_, err := c.sendPatchSubmissionCompleted(ctx, params)
return err
}
func (c *Client) sendPatchSubmissionCompleted(ctx context.Context, params PatchSubmissionCompletedParams) (res *PatchSubmissionCompletedOK, err error) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("patchSubmissionCompleted"),
semconv.HTTPRequestMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/completed"),
}
// Run stopwatch.
startTime := time.Now()
defer func() {
// Use floating point division here for higher precision (instead of Millisecond method).
elapsedDuration := time.Since(startTime)
c.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...))
}()
// Increment request counter.
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
// Start a span for this request.
ctx, span := c.cfg.Tracer.Start(ctx, "PatchSubmissionCompleted",
trace.WithAttributes(otelAttrs...),
clientSpanKind,
)
// Track stage for error reporting.
var stage string
defer func() {
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
}
span.End()
}()
stage = "BuildURL"
u := uri.Clone(c.requestURL(ctx))
var pathParts [3]string
pathParts[0] = "/submissions/"
2024-11-26 01:22:45 +00:00
{
2024-11-26 20:39:10 +00:00
// Encode "SubmissionID" parameter.
e := uri.NewPathEncoder(uri.PathEncoderConfig{
Param: "SubmissionID",
Style: uri.PathStyleSimple,
Explode: false,
})
if err := func() error {
return e.EncodeValue(conv.Int64ToString(params.SubmissionID))
}(); err != nil {
return res, errors.Wrap(err, "encode path")
}
encoded, err := e.Result()
if err != nil {
return res, errors.Wrap(err, "encode path")
}
pathParts[1] = encoded
}
pathParts[2] = "/completed"
uri.AddPathParts(u, pathParts[:]...)
2024-11-26 01:22:45 +00:00
stage = "EncodeRequest"
2024-11-26 20:39:10 +00:00
r, err := ht.NewRequest(ctx, "PATCH", u)
2024-11-26 01:22:45 +00:00
if err != nil {
return res, errors.Wrap(err, "create request")
}
stage = "SendRequest"
resp, err := c.cfg.Client.Do(r)
if err != nil {
return res, errors.Wrap(err, "do request")
}
defer resp.Body.Close()
stage = "DecodeResponse"
2024-11-26 20:39:10 +00:00
result, err := decodePatchSubmissionCompletedResponse(resp)
2024-11-26 01:22:45 +00:00
if err != nil {
return res, errors.Wrap(err, "decode response")
}
return result, nil
}
2024-11-26 20:39:10 +00:00
// PatchSubmissionModel invokes patchSubmissionModel operation.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// Update model following role restrictions.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// PATCH /submissions/{SubmissionID}/model
func (c *Client) PatchSubmissionModel(ctx context.Context, params PatchSubmissionModelParams) error {
_, err := c.sendPatchSubmissionModel(ctx, params)
return err
2024-11-26 01:22:45 +00:00
}
2024-11-26 20:39:10 +00:00
func (c *Client) sendPatchSubmissionModel(ctx context.Context, params PatchSubmissionModelParams) (res *PatchSubmissionModelOK, err error) {
2024-11-26 01:22:45 +00:00
otelAttrs := []attribute.KeyValue{
2024-11-26 20:39:10 +00:00
otelogen.OperationID("patchSubmissionModel"),
semconv.HTTPRequestMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/model"),
2024-11-26 01:22:45 +00:00
}
// Run stopwatch.
startTime := time.Now()
defer func() {
// Use floating point division here for higher precision (instead of Millisecond method).
elapsedDuration := time.Since(startTime)
c.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...))
}()
// Increment request counter.
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
// Start a span for this request.
2024-11-26 20:39:10 +00:00
ctx, span := c.cfg.Tracer.Start(ctx, "PatchSubmissionModel",
2024-11-26 01:22:45 +00:00
trace.WithAttributes(otelAttrs...),
clientSpanKind,
)
// Track stage for error reporting.
var stage string
defer func() {
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
}
span.End()
}()
stage = "BuildURL"
u := uri.Clone(c.requestURL(ctx))
2024-11-26 20:39:10 +00:00
var pathParts [3]string
pathParts[0] = "/submissions/"
{
// Encode "SubmissionID" parameter.
e := uri.NewPathEncoder(uri.PathEncoderConfig{
Param: "SubmissionID",
Style: uri.PathStyleSimple,
Explode: false,
})
if err := func() error {
return e.EncodeValue(conv.Int64ToString(params.SubmissionID))
}(); err != nil {
return res, errors.Wrap(err, "encode path")
}
encoded, err := e.Result()
if err != nil {
return res, errors.Wrap(err, "encode path")
}
pathParts[1] = encoded
}
pathParts[2] = "/model"
2024-11-26 01:22:45 +00:00
uri.AddPathParts(u, pathParts[:]...)
stage = "EncodeQueryParams"
q := uri.NewQueryEncoder()
{
2024-11-26 20:39:10 +00:00
// Encode "ModelID" parameter.
2024-11-26 01:22:45 +00:00
cfg := uri.QueryParameterEncodingConfig{
2024-11-26 20:39:10 +00:00
Name: "ModelID",
2024-11-26 01:22:45 +00:00
Style: uri.QueryStyleForm,
Explode: true,
}
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
2024-11-26 20:39:10 +00:00
return e.EncodeValue(conv.Int64ToString(params.ModelID))
2024-11-26 01:22:45 +00:00
}); err != nil {
return res, errors.Wrap(err, "encode query")
}
}
{
2024-11-26 20:39:10 +00:00
// Encode "VersionID" parameter.
2024-11-26 01:22:45 +00:00
cfg := uri.QueryParameterEncodingConfig{
2024-11-26 20:39:10 +00:00
Name: "VersionID",
2024-11-26 01:22:45 +00:00
Style: uri.QueryStyleForm,
Explode: true,
}
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
2024-11-26 20:39:10 +00:00
return e.EncodeValue(conv.Int64ToString(params.VersionID))
2024-11-26 01:22:45 +00:00
}); err != nil {
return res, errors.Wrap(err, "encode query")
}
}
u.RawQuery = q.Values().Encode()
stage = "EncodeRequest"
2024-11-26 20:39:10 +00:00
r, err := ht.NewRequest(ctx, "PATCH", u)
2024-11-26 01:22:45 +00:00
if err != nil {
return res, errors.Wrap(err, "create request")
}
stage = "SendRequest"
resp, err := c.cfg.Client.Do(r)
if err != nil {
return res, errors.Wrap(err, "do request")
}
defer resp.Body.Close()
stage = "DecodeResponse"
2024-11-26 20:39:10 +00:00
result, err := decodePatchSubmissionModelResponse(resp)
2024-11-26 01:22:45 +00:00
if err != nil {
return res, errors.Wrap(err, "decode response")
}
return result, nil
}
2024-11-26 20:39:10 +00:00
// PatchSubmissionStatus invokes patchSubmissionStatus operation.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// Update status following role restrictions.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// PATCH /submissions/{SubmissionID}/status
func (c *Client) PatchSubmissionStatus(ctx context.Context, params PatchSubmissionStatusParams) error {
_, err := c.sendPatchSubmissionStatus(ctx, params)
return err
2024-11-26 01:22:45 +00:00
}
2024-11-26 20:39:10 +00:00
func (c *Client) sendPatchSubmissionStatus(ctx context.Context, params PatchSubmissionStatusParams) (res *PatchSubmissionStatusOK, err error) {
2024-11-26 01:22:45 +00:00
otelAttrs := []attribute.KeyValue{
2024-11-26 20:39:10 +00:00
otelogen.OperationID("patchSubmissionStatus"),
semconv.HTTPRequestMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status"),
2024-11-26 01:22:45 +00:00
}
// Run stopwatch.
startTime := time.Now()
defer func() {
// Use floating point division here for higher precision (instead of Millisecond method).
elapsedDuration := time.Since(startTime)
c.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...))
}()
// Increment request counter.
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
// Start a span for this request.
2024-11-26 20:39:10 +00:00
ctx, span := c.cfg.Tracer.Start(ctx, "PatchSubmissionStatus",
2024-11-26 01:22:45 +00:00
trace.WithAttributes(otelAttrs...),
clientSpanKind,
)
// Track stage for error reporting.
var stage string
defer func() {
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
}
span.End()
}()
stage = "BuildURL"
u := uri.Clone(c.requestURL(ctx))
2024-11-26 20:39:10 +00:00
var pathParts [3]string
pathParts[0] = "/submissions/"
2024-11-26 01:22:45 +00:00
{
2024-11-26 20:39:10 +00:00
// Encode "SubmissionID" parameter.
e := uri.NewPathEncoder(uri.PathEncoderConfig{
Param: "SubmissionID",
Style: uri.PathStyleSimple,
Explode: false,
})
if err := func() error {
return e.EncodeValue(conv.Int64ToString(params.SubmissionID))
}(); err != nil {
return res, errors.Wrap(err, "encode path")
2024-11-26 01:22:45 +00:00
}
2024-11-26 20:39:10 +00:00
encoded, err := e.Result()
if err != nil {
return res, errors.Wrap(err, "encode path")
2024-11-26 01:22:45 +00:00
}
2024-11-26 20:39:10 +00:00
pathParts[1] = encoded
2024-11-26 01:22:45 +00:00
}
2024-11-26 20:39:10 +00:00
pathParts[2] = "/status"
uri.AddPathParts(u, pathParts[:]...)
stage = "EncodeQueryParams"
q := uri.NewQueryEncoder()
2024-11-26 01:22:45 +00:00
{
2024-11-26 20:39:10 +00:00
// Encode "Status" parameter.
2024-11-26 01:22:45 +00:00
cfg := uri.QueryParameterEncodingConfig{
2024-11-26 20:39:10 +00:00
Name: "Status",
2024-11-26 01:22:45 +00:00
Style: uri.QueryStyleForm,
Explode: true,
}
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
2024-11-26 20:39:10 +00:00
return e.EncodeValue(conv.Int32ToString(params.Status))
2024-11-26 01:22:45 +00:00
}); err != nil {
return res, errors.Wrap(err, "encode query")
}
}
u.RawQuery = q.Values().Encode()
stage = "EncodeRequest"
2024-11-26 20:39:10 +00:00
r, err := ht.NewRequest(ctx, "PATCH", u)
2024-11-26 01:22:45 +00:00
if err != nil {
return res, errors.Wrap(err, "create request")
}
stage = "SendRequest"
resp, err := c.cfg.Client.Do(r)
if err != nil {
return res, errors.Wrap(err, "do request")
}
defer resp.Body.Close()
stage = "DecodeResponse"
2024-11-26 20:39:10 +00:00
result, err := decodePatchSubmissionStatusResponse(resp)
2024-11-26 01:22:45 +00:00
if err != nil {
return res, errors.Wrap(err, "decode response")
}
return result, nil
}