350 lines
8.4 KiB
Go
350 lines
8.4 KiB
Go
// Code generated by ogen, DO NOT EDIT.
|
|
|
|
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/go-faster/errors"
|
|
"github.com/go-faster/jx"
|
|
"go.opentelemetry.io/otel/codes"
|
|
"go.opentelemetry.io/otel/trace"
|
|
|
|
ht "github.com/ogen-go/ogen/http"
|
|
)
|
|
|
|
func encodeGroupsGetResponse(response []Group, w http.ResponseWriter, span trace.Span) error {
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(200)
|
|
span.SetStatus(codes.Ok, http.StatusText(200))
|
|
|
|
e := new(jx.Encoder)
|
|
e.ArrStart()
|
|
for _, elem := range response {
|
|
elem.Encode(e)
|
|
}
|
|
e.ArrEnd()
|
|
if _, err := e.WriteTo(w); err != nil {
|
|
return errors.Wrap(err, "write")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func encodeGroupsIDDeleteResponse(response GroupsIDDeleteRes, w http.ResponseWriter, span trace.Span) error {
|
|
switch response := response.(type) {
|
|
case *Ok:
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(200)
|
|
span.SetStatus(codes.Ok, http.StatusText(200))
|
|
|
|
e := new(jx.Encoder)
|
|
response.Encode(e)
|
|
if _, err := e.WriteTo(w); err != nil {
|
|
return errors.Wrap(err, "write")
|
|
}
|
|
|
|
return nil
|
|
|
|
case *Error:
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(404)
|
|
span.SetStatus(codes.Error, http.StatusText(404))
|
|
|
|
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 encodeGroupsIDGetResponse(response GroupsIDGetRes, w http.ResponseWriter, span trace.Span) error {
|
|
switch response := response.(type) {
|
|
case *Group:
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(200)
|
|
span.SetStatus(codes.Ok, http.StatusText(200))
|
|
|
|
e := new(jx.Encoder)
|
|
response.Encode(e)
|
|
if _, err := e.WriteTo(w); err != nil {
|
|
return errors.Wrap(err, "write")
|
|
}
|
|
|
|
return nil
|
|
|
|
case *Error:
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(404)
|
|
span.SetStatus(codes.Error, http.StatusText(404))
|
|
|
|
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 encodeGroupsIDPutResponse(response GroupsIDPutRes, w http.ResponseWriter, span trace.Span) error {
|
|
switch response := response.(type) {
|
|
case *Group:
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(200)
|
|
span.SetStatus(codes.Ok, http.StatusText(200))
|
|
|
|
e := new(jx.Encoder)
|
|
response.Encode(e)
|
|
if _, err := e.WriteTo(w); err != nil {
|
|
return errors.Wrap(err, "write")
|
|
}
|
|
|
|
return nil
|
|
|
|
case *Error:
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(404)
|
|
span.SetStatus(codes.Error, http.StatusText(404))
|
|
|
|
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 encodeGroupsPostResponse(response *Group, w http.ResponseWriter, span trace.Span) error {
|
|
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
|
|
}
|
|
|
|
func encodeHealthzGetResponse(response *Ok, w http.ResponseWriter, span trace.Span) error {
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(200)
|
|
span.SetStatus(codes.Ok, http.StatusText(200))
|
|
|
|
e := new(jx.Encoder)
|
|
response.Encode(e)
|
|
if _, err := e.WriteTo(w); err != nil {
|
|
return errors.Wrap(err, "write")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func encodeUsersGetResponse(response []User, w http.ResponseWriter, span trace.Span) error {
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(200)
|
|
span.SetStatus(codes.Ok, http.StatusText(200))
|
|
|
|
e := new(jx.Encoder)
|
|
e.ArrStart()
|
|
for _, elem := range response {
|
|
elem.Encode(e)
|
|
}
|
|
e.ArrEnd()
|
|
if _, err := e.WriteTo(w); err != nil {
|
|
return errors.Wrap(err, "write")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func encodeUsersIDDeleteResponse(response UsersIDDeleteRes, w http.ResponseWriter, span trace.Span) error {
|
|
switch response := response.(type) {
|
|
case *Ok:
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(200)
|
|
span.SetStatus(codes.Ok, http.StatusText(200))
|
|
|
|
e := new(jx.Encoder)
|
|
response.Encode(e)
|
|
if _, err := e.WriteTo(w); err != nil {
|
|
return errors.Wrap(err, "write")
|
|
}
|
|
|
|
return nil
|
|
|
|
case *Error:
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(404)
|
|
span.SetStatus(codes.Error, http.StatusText(404))
|
|
|
|
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 encodeUsersIDGetResponse(response UsersIDGetRes, w http.ResponseWriter, span trace.Span) error {
|
|
switch response := response.(type) {
|
|
case *User:
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(200)
|
|
span.SetStatus(codes.Ok, http.StatusText(200))
|
|
|
|
e := new(jx.Encoder)
|
|
response.Encode(e)
|
|
if _, err := e.WriteTo(w); err != nil {
|
|
return errors.Wrap(err, "write")
|
|
}
|
|
|
|
return nil
|
|
|
|
case *Error:
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(404)
|
|
span.SetStatus(codes.Error, http.StatusText(404))
|
|
|
|
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 encodeUsersIDGroupPutResponse(response UsersIDGroupPutRes, w http.ResponseWriter, span trace.Span) error {
|
|
switch response := response.(type) {
|
|
case *User:
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(200)
|
|
span.SetStatus(codes.Ok, http.StatusText(200))
|
|
|
|
e := new(jx.Encoder)
|
|
response.Encode(e)
|
|
if _, err := e.WriteTo(w); err != nil {
|
|
return errors.Wrap(err, "write")
|
|
}
|
|
|
|
return nil
|
|
|
|
case *Error:
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(404)
|
|
span.SetStatus(codes.Error, http.StatusText(404))
|
|
|
|
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 encodeUsersIDPutResponse(response UsersIDPutRes, w http.ResponseWriter, span trace.Span) error {
|
|
switch response := response.(type) {
|
|
case *User:
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(200)
|
|
span.SetStatus(codes.Ok, http.StatusText(200))
|
|
|
|
e := new(jx.Encoder)
|
|
response.Encode(e)
|
|
if _, err := e.WriteTo(w); err != nil {
|
|
return errors.Wrap(err, "write")
|
|
}
|
|
|
|
return nil
|
|
|
|
case *Error:
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(404)
|
|
span.SetStatus(codes.Error, http.StatusText(404))
|
|
|
|
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 encodeUsersPostResponse(response *User, w http.ResponseWriter, span trace.Span) error {
|
|
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
|
|
}
|
|
|
|
func encodeErrorResponse(response *ErrorStatusCode, w http.ResponseWriter, span trace.Span) error {
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
code := response.StatusCode
|
|
if code == 0 {
|
|
// Set default status code.
|
|
code = http.StatusOK
|
|
}
|
|
w.WriteHeader(code)
|
|
if st := http.StatusText(code); code >= http.StatusBadRequest {
|
|
span.SetStatus(codes.Error, st)
|
|
} else {
|
|
span.SetStatus(codes.Ok, st)
|
|
}
|
|
|
|
e := new(jx.Encoder)
|
|
response.Response.Encode(e)
|
|
if _, err := e.WriteTo(w); err != nil {
|
|
return errors.Wrap(err, "write")
|
|
}
|
|
|
|
if code >= http.StatusInternalServerError {
|
|
return errors.Wrapf(ht.ErrInternalServerErrorResponse, "code: %d, message: %s", code, http.StatusText(code))
|
|
}
|
|
return nil
|
|
|
|
}
|