// Code generated by ogen, DO NOT EDIT. package oas import ( "net/http" "github.com/go-faster/errors" "github.com/go-faster/jx" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" "github.com/ogen-go/ogen/conv" "github.com/ogen-go/ogen/uri" ) func encodeCreateShortURLResponse(response CreateShortURLRes, w http.ResponseWriter, span trace.Span) error { switch response := response.(type) { case *CreateShortURLCreated: w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(201) span.SetStatus(codes.Ok, http.StatusText(201)) e := new(jx.Encoder) response.Encode(e) if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } return nil case *CreateShortURLBadRequest: w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(400) span.SetStatus(codes.Error, http.StatusText(400)) e := new(jx.Encoder) response.Encode(e) if _, err := e.WriteTo(w); err != nil { return errors.Wrap(err, "write") } return nil default: return errors.Errorf("unexpected response type: %T", response) } } func encodeRedirectLongURLResponse(response RedirectLongURLRes, w http.ResponseWriter, span trace.Span) error { switch response := response.(type) { case *RedirectLongURLTemporaryRedirect: // Encoding response headers. { h := uri.NewHeaderEncoder(w.Header()) // Encode "Location" header. { cfg := uri.HeaderParameterEncodingConfig{ Name: "Location", Explode: false, } if err := h.EncodeParam(cfg, func(e uri.Encoder) error { if val, ok := response.Location.Get(); ok { return e.EncodeValue(conv.StringToString(val)) } return nil }); err != nil { return errors.Wrap(err, "encode Location header") } } } w.WriteHeader(307) span.SetStatus(codes.Ok, http.StatusText(307)) return nil case *RedirectLongURLNotFound: w.WriteHeader(404) span.SetStatus(codes.Error, http.StatusText(404)) return nil default: return errors.Errorf("unexpected response type: %T", response) } }