-
Notifications
You must be signed in to change notification settings - Fork 0
/
student_service_esdk.pb.go
139 lines (109 loc) · 3.03 KB
/
student_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
// 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 course
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 _StudentServiceHttpClient interface {
Do(*http.Request) (*http.Response, error)
}
type StudentServiceService struct {
base string
cli _StudentServiceHttpClient
}
// NewStudentServiceHttpClient constructs client for StudentService
func NewStudentServiceHttpClient(url string, cli _StudentServiceHttpClient) *StudentServiceService {
if url == "" {
url = os.Getenv("EOLYMP_API_URL")
if url == "" {
url = "https://api.eolymp.com"
}
}
return &StudentServiceService{base: url, cli: cli}
}
func (s *StudentServiceService) 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 *StudentServiceService) DescribeStudent(ctx context.Context, in *DescribeStudentInput) (*DescribeStudentOutput, error) {
out := &DescribeStudentOutput{}
path := "/students/" + url.PathEscape(in.GetMemberId())
// Cleanup URL parameters to avoid any ambiguity
if in != nil {
in.MemberId = ""
}
if err := s.do(ctx, "GET", path, in, out); err != nil {
return nil, err
}
return out, nil
}
func (s *StudentServiceService) DescribeViewer(ctx context.Context, in *DescribeViewerInput) (*DescribeViewerOutput, error) {
out := &DescribeViewerOutput{}
path := "/viewer/student"
if err := s.do(ctx, "GET", path, in, out); err != nil {
return nil, err
}
return out, nil
}
func (s *StudentServiceService) ListStudents(ctx context.Context, in *ListStudentsInput) (*ListStudentsOutput, error) {
out := &ListStudentsOutput{}
path := "/students"
if err := s.do(ctx, "GET", path, in, out); err != nil {
return nil, err
}
return out, nil
}