-
Notifications
You must be signed in to change notification settings - Fork 0
/
attachment_service_esdk.pb.go
171 lines (133 loc) · 3.95 KB
/
attachment_service_esdk.pb.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Code generated by protoc-gen-go-esdk. DO NOT EDIT.
// See https://github.com/eolymp/contracts/tree/main/cmd/protoc-gen-go-esdk for more details.
package atlas
import (
bytes "bytes"
context "context"
fmt "fmt"
protojson "google.golang.org/protobuf/encoding/protojson"
proto "google.golang.org/protobuf/proto"
io "io"
ioutil "io/ioutil"
http "net/http"
url "net/url"
os "os"
)
type _AttachmentServiceHttpClient interface {
Do(*http.Request) (*http.Response, error)
}
type AttachmentServiceService struct {
base string
cli _AttachmentServiceHttpClient
}
// NewAttachmentServiceHttpClient constructs client for AttachmentService
func NewAttachmentServiceHttpClient(url string, cli _AttachmentServiceHttpClient) *AttachmentServiceService {
if url == "" {
url = os.Getenv("EOLYMP_API_URL")
if url == "" {
url = "https://api.eolymp.com"
}
}
return &AttachmentServiceService{base: url, cli: cli}
}
func (s *AttachmentServiceService) do(ctx context.Context, verb, path string, in, out proto.Message) (err error) {
var body io.Reader
if in != nil {
data, err := protojson.Marshal(in)
if err != nil {
return err
}
if verb != "GET" {
body = bytes.NewReader(data)
} else {
query := url.Values{"q": []string{string(data)}}
path = path + "?" + query.Encode()
}
}
if in == nil && verb != "GET" {
body = bytes.NewReader([]byte("{}"))
}
req, err := http.NewRequest(verb, s.base+path, body)
if err != nil {
return err
}
req.Header.Set("Accept", "application/json")
req.Header.Set("Content-Type", "application/json")
req = req.WithContext(ctx)
resp, err := s.cli.Do(req)
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
if err != nil {
return err
}
if resp.StatusCode != 200 {
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("non-200 response code (%v)", resp.StatusCode)
}
return fmt.Errorf("non-200 response code (%v): %s", resp.StatusCode, data)
}
if out != nil {
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
if err := protojson.Unmarshal(data, out); err != nil {
return err
}
}
return nil
}
func (s *AttachmentServiceService) CreateAttachment(ctx context.Context, in *CreateAttachmentInput) (*CreateAttachmentOutput, error) {
out := &CreateAttachmentOutput{}
path := "/attachments"
if err := s.do(ctx, "POST", path, in, out); err != nil {
return nil, err
}
return out, nil
}
func (s *AttachmentServiceService) UpdateAttachment(ctx context.Context, in *UpdateAttachmentInput) (*UpdateAttachmentOutput, error) {
out := &UpdateAttachmentOutput{}
path := "/attachments/" + url.PathEscape(in.GetAttachmentId())
// Cleanup URL parameters to avoid any ambiguity
if in != nil {
in.AttachmentId = ""
}
if err := s.do(ctx, "POST", path, in, out); err != nil {
return nil, err
}
return out, nil
}
func (s *AttachmentServiceService) DeleteAttachment(ctx context.Context, in *DeleteAttachmentInput) (*DeleteAttachmentOutput, error) {
out := &DeleteAttachmentOutput{}
path := "/attachments/" + url.PathEscape(in.GetAttachmentId())
// Cleanup URL parameters to avoid any ambiguity
if in != nil {
in.AttachmentId = ""
}
if err := s.do(ctx, "DELETE", path, in, out); err != nil {
return nil, err
}
return out, nil
}
func (s *AttachmentServiceService) ListAttachments(ctx context.Context, in *ListAttachmentsInput) (*ListAttachmentsOutput, error) {
out := &ListAttachmentsOutput{}
path := "/attachments"
if err := s.do(ctx, "GET", path, in, out); err != nil {
return nil, err
}
return out, nil
}
func (s *AttachmentServiceService) DescribeAttachment(ctx context.Context, in *DescribeAttachmentInput) (*DescribeAttachmentOutput, error) {
out := &DescribeAttachmentOutput{}
path := "/attachments/" + url.PathEscape(in.GetAttachmentId())
// Cleanup URL parameters to avoid any ambiguity
if in != nil {
in.AttachmentId = ""
}
if err := s.do(ctx, "GET", path, in, out); err != nil {
return nil, err
}
return out, nil
}