-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookmark_service_esdk.pb.go
123 lines (97 loc) · 2.62 KB
/
bookmark_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
// 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 _BookmarkServiceHttpClient interface {
Do(*http.Request) (*http.Response, error)
}
type BookmarkServiceService struct {
base string
cli _BookmarkServiceHttpClient
}
// NewBookmarkServiceHttpClient constructs client for BookmarkService
func NewBookmarkServiceHttpClient(url string, cli _BookmarkServiceHttpClient) *BookmarkServiceService {
if url == "" {
url = os.Getenv("EOLYMP_API_URL")
if url == "" {
url = "https://api.eolymp.com"
}
}
return &BookmarkServiceService{base: url, cli: cli}
}
func (s *BookmarkServiceService) 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 *BookmarkServiceService) GetBookmark(ctx context.Context, in *GetBookmarkInput) (*GetBookmarkOutput, error) {
out := &GetBookmarkOutput{}
path := "/bookmark"
if err := s.do(ctx, "GET", path, in, out); err != nil {
return nil, err
}
return out, nil
}
func (s *BookmarkServiceService) SetBookmark(ctx context.Context, in *SetBookmarkInput) (*SetBookmarkOutput, error) {
out := &SetBookmarkOutput{}
path := "/bookmark"
if err := s.do(ctx, "POST", path, in, out); err != nil {
return nil, err
}
return out, nil
}