-
Notifications
You must be signed in to change notification settings - Fork 0
/
oas_response_encoders_gen.go
69 lines (51 loc) · 1.5 KB
/
oas_response_encoders_gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// 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"
)
func encodeHealthResponse(response HealthRes, w http.ResponseWriter, span trace.Span) error {
switch response := response.(type) {
case *HealthOK:
w.WriteHeader(200)
span.SetStatus(codes.Ok, http.StatusText(200))
return nil
case *HealthInternalServerError:
w.WriteHeader(500)
span.SetStatus(codes.Error, http.StatusText(500))
return nil
default:
return errors.Errorf("unexpected response type: %T", response)
}
}
func encodeListClusterResponse(response ListClusterRes, w http.ResponseWriter, span trace.Span) error {
switch response := response.(type) {
case *ListClusterResponse:
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 *ListClusterBadRequest:
w.WriteHeader(400)
span.SetStatus(codes.Error, http.StatusText(400))
return nil
case *ListClusterNotFound:
w.WriteHeader(404)
span.SetStatus(codes.Error, http.StatusText(404))
return nil
case *ListClusterInternalServerError:
w.WriteHeader(500)
span.SetStatus(codes.Error, http.StatusText(500))
return nil
default:
return errors.Errorf("unexpected response type: %T", response)
}
}