// Code generated by ogen, DO NOT EDIT. package oas import ( "io" "mime" "net/http" "github.com/go-faster/errors" "github.com/go-faster/jx" "github.com/ogen-go/ogen/conv" "github.com/ogen-go/ogen/ogenerrors" "github.com/ogen-go/ogen/uri" "github.com/ogen-go/ogen/validate" ) func decodeCreateShortURLResponse(resp *http.Response) (res CreateShortURLRes, _ error) { switch resp.StatusCode { case 201: // Code 201. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response CreateShortURLCreated if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &response, nil default: return res, validate.InvalidContentType(ct) } case 400: // Code 400. ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) if err != nil { return res, errors.Wrap(err, "parse media type") } switch { case ct == "application/json": buf, err := io.ReadAll(resp.Body) if err != nil { return res, err } d := jx.DecodeBytes(buf) var response CreateShortURLBadRequest if err := func() error { if err := response.Decode(d); err != nil { return err } if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } return nil }(); err != nil { err = &ogenerrors.DecodeBodyError{ ContentType: ct, Body: buf, Err: err, } return res, err } return &response, nil default: return res, validate.InvalidContentType(ct) } } return res, validate.UnexpectedStatusCode(resp.StatusCode) } func decodeRedirectLongURLResponse(resp *http.Response) (res RedirectLongURLRes, _ error) { switch resp.StatusCode { case 307: // Code 307. var wrapper RedirectLongURLTemporaryRedirect h := uri.NewHeaderDecoder(resp.Header) // Parse "Location" header. { cfg := uri.HeaderParameterDecodingConfig{ Name: "Location", Explode: false, } if err := func() error { if err := h.HasParam(cfg); err == nil { if err := h.DecodeParam(cfg, func(d uri.Decoder) error { var wrapperDotLocationVal string if err := func() error { val, err := d.DecodeValue() if err != nil { return err } c, err := conv.ToString(val) if err != nil { return err } wrapperDotLocationVal = c return nil }(); err != nil { return err } wrapper.Location.SetTo(wrapperDotLocationVal) return nil }); err != nil { return err } } return nil }(); err != nil { return res, errors.Wrap(err, "parse Location header") } } return &wrapper, nil case 404: // Code 404. return &RedirectLongURLNotFound{}, nil } return res, validate.UnexpectedStatusCode(resp.StatusCode) }