short/internal/oas/oas_parameters_gen.go

83 lines
1.6 KiB
Go
Raw Permalink Normal View History

2024-01-29 18:32:16 +00:00
// Code generated by ogen, DO NOT EDIT.
package oas
import (
"net/http"
"net/url"
"github.com/go-faster/errors"
"github.com/ogen-go/ogen/conv"
"github.com/ogen-go/ogen/middleware"
"github.com/ogen-go/ogen/ogenerrors"
"github.com/ogen-go/ogen/uri"
"github.com/ogen-go/ogen/validate"
)
// RedirectLongURLParams is parameters of redirectLongURL operation.
type RedirectLongURLParams struct {
2024-01-29 18:32:16 +00:00
// Hash of shorten URL.
Hash string
}
func unpackRedirectLongURLParams(packed middleware.Parameters) (params RedirectLongURLParams) {
2024-01-29 18:32:16 +00:00
{
key := middleware.ParameterKey{
Name: "hash",
In: "path",
}
params.Hash = packed[key].(string)
}
return params
}
func decodeRedirectLongURLParams(args [1]string, argsEscaped bool, r *http.Request) (params RedirectLongURLParams, _ error) {
2024-01-29 18:32:16 +00:00
// Decode path: hash.
if err := func() error {
param := args[0]
if argsEscaped {
unescaped, err := url.PathUnescape(args[0])
if err != nil {
return errors.Wrap(err, "unescape path")
}
param = unescaped
}
if len(param) > 0 {
d := uri.NewPathDecoder(uri.PathDecoderConfig{
Param: "hash",
Value: param,
Style: uri.PathStyleSimple,
Explode: false,
})
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToString(val)
if err != nil {
return err
}
params.Hash = c
return nil
}(); err != nil {
return err
}
} else {
return validate.ErrFieldRequired
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "hash",
In: "path",
Err: err,
}
}
return params, nil
}