Improve binapi generator
[govpp.git] / binapi / gbp / gbp_rest.ba.go
1 // Code generated by GoVPP's binapi-generator. DO NOT EDIT.
2
3 package gbp
4
5 import (
6         "encoding/json"
7         "io/ioutil"
8         "net/http"
9 )
10
11 func RESTHandler(rpc RPCService) http.Handler {
12         mux := http.NewServeMux()
13         mux.HandleFunc("/gbp_bridge_domain_add", func(w http.ResponseWriter, req *http.Request) {
14                 var request = new(GbpBridgeDomainAdd)
15                 b, err := ioutil.ReadAll(req.Body)
16                 if err != nil {
17                         http.Error(w, "read body failed", http.StatusBadRequest)
18                         return
19                 }
20                 if err := json.Unmarshal(b, request); err != nil {
21                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
22                         return
23                 }
24                 reply, err := rpc.GbpBridgeDomainAdd(req.Context(), request)
25                 if err != nil {
26                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
27                         return
28                 }
29                 rep, err := json.MarshalIndent(reply, "", "  ")
30                 if err != nil {
31                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
32                         return
33                 }
34                 w.Write(rep)
35         })
36         mux.HandleFunc("/gbp_bridge_domain_del", func(w http.ResponseWriter, req *http.Request) {
37                 var request = new(GbpBridgeDomainDel)
38                 b, err := ioutil.ReadAll(req.Body)
39                 if err != nil {
40                         http.Error(w, "read body failed", http.StatusBadRequest)
41                         return
42                 }
43                 if err := json.Unmarshal(b, request); err != nil {
44                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
45                         return
46                 }
47                 reply, err := rpc.GbpBridgeDomainDel(req.Context(), request)
48                 if err != nil {
49                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
50                         return
51                 }
52                 rep, err := json.MarshalIndent(reply, "", "  ")
53                 if err != nil {
54                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
55                         return
56                 }
57                 w.Write(rep)
58         })
59         mux.HandleFunc("/gbp_contract_add_del", func(w http.ResponseWriter, req *http.Request) {
60                 var request = new(GbpContractAddDel)
61                 b, err := ioutil.ReadAll(req.Body)
62                 if err != nil {
63                         http.Error(w, "read body failed", http.StatusBadRequest)
64                         return
65                 }
66                 if err := json.Unmarshal(b, request); err != nil {
67                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
68                         return
69                 }
70                 reply, err := rpc.GbpContractAddDel(req.Context(), request)
71                 if err != nil {
72                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
73                         return
74                 }
75                 rep, err := json.MarshalIndent(reply, "", "  ")
76                 if err != nil {
77                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
78                         return
79                 }
80                 w.Write(rep)
81         })
82         mux.HandleFunc("/gbp_endpoint_add", func(w http.ResponseWriter, req *http.Request) {
83                 var request = new(GbpEndpointAdd)
84                 b, err := ioutil.ReadAll(req.Body)
85                 if err != nil {
86                         http.Error(w, "read body failed", http.StatusBadRequest)
87                         return
88                 }
89                 if err := json.Unmarshal(b, request); err != nil {
90                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
91                         return
92                 }
93                 reply, err := rpc.GbpEndpointAdd(req.Context(), request)
94                 if err != nil {
95                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
96                         return
97                 }
98                 rep, err := json.MarshalIndent(reply, "", "  ")
99                 if err != nil {
100                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
101                         return
102                 }
103                 w.Write(rep)
104         })
105         mux.HandleFunc("/gbp_endpoint_del", func(w http.ResponseWriter, req *http.Request) {
106                 var request = new(GbpEndpointDel)
107                 b, err := ioutil.ReadAll(req.Body)
108                 if err != nil {
109                         http.Error(w, "read body failed", http.StatusBadRequest)
110                         return
111                 }
112                 if err := json.Unmarshal(b, request); err != nil {
113                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
114                         return
115                 }
116                 reply, err := rpc.GbpEndpointDel(req.Context(), request)
117                 if err != nil {
118                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
119                         return
120                 }
121                 rep, err := json.MarshalIndent(reply, "", "  ")
122                 if err != nil {
123                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
124                         return
125                 }
126                 w.Write(rep)
127         })
128         mux.HandleFunc("/gbp_endpoint_group_add", func(w http.ResponseWriter, req *http.Request) {
129                 var request = new(GbpEndpointGroupAdd)
130                 b, err := ioutil.ReadAll(req.Body)
131                 if err != nil {
132                         http.Error(w, "read body failed", http.StatusBadRequest)
133                         return
134                 }
135                 if err := json.Unmarshal(b, request); err != nil {
136                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
137                         return
138                 }
139                 reply, err := rpc.GbpEndpointGroupAdd(req.Context(), request)
140                 if err != nil {
141                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
142                         return
143                 }
144                 rep, err := json.MarshalIndent(reply, "", "  ")
145                 if err != nil {
146                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
147                         return
148                 }
149                 w.Write(rep)
150         })
151         mux.HandleFunc("/gbp_endpoint_group_del", func(w http.ResponseWriter, req *http.Request) {
152                 var request = new(GbpEndpointGroupDel)
153                 b, err := ioutil.ReadAll(req.Body)
154                 if err != nil {
155                         http.Error(w, "read body failed", http.StatusBadRequest)
156                         return
157                 }
158                 if err := json.Unmarshal(b, request); err != nil {
159                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
160                         return
161                 }
162                 reply, err := rpc.GbpEndpointGroupDel(req.Context(), request)
163                 if err != nil {
164                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
165                         return
166                 }
167                 rep, err := json.MarshalIndent(reply, "", "  ")
168                 if err != nil {
169                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
170                         return
171                 }
172                 w.Write(rep)
173         })
174         mux.HandleFunc("/gbp_ext_itf_add_del", func(w http.ResponseWriter, req *http.Request) {
175                 var request = new(GbpExtItfAddDel)
176                 b, err := ioutil.ReadAll(req.Body)
177                 if err != nil {
178                         http.Error(w, "read body failed", http.StatusBadRequest)
179                         return
180                 }
181                 if err := json.Unmarshal(b, request); err != nil {
182                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
183                         return
184                 }
185                 reply, err := rpc.GbpExtItfAddDel(req.Context(), request)
186                 if err != nil {
187                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
188                         return
189                 }
190                 rep, err := json.MarshalIndent(reply, "", "  ")
191                 if err != nil {
192                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
193                         return
194                 }
195                 w.Write(rep)
196         })
197         mux.HandleFunc("/gbp_recirc_add_del", func(w http.ResponseWriter, req *http.Request) {
198                 var request = new(GbpRecircAddDel)
199                 b, err := ioutil.ReadAll(req.Body)
200                 if err != nil {
201                         http.Error(w, "read body failed", http.StatusBadRequest)
202                         return
203                 }
204                 if err := json.Unmarshal(b, request); err != nil {
205                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
206                         return
207                 }
208                 reply, err := rpc.GbpRecircAddDel(req.Context(), request)
209                 if err != nil {
210                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
211                         return
212                 }
213                 rep, err := json.MarshalIndent(reply, "", "  ")
214                 if err != nil {
215                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
216                         return
217                 }
218                 w.Write(rep)
219         })
220         mux.HandleFunc("/gbp_route_domain_add", func(w http.ResponseWriter, req *http.Request) {
221                 var request = new(GbpRouteDomainAdd)
222                 b, err := ioutil.ReadAll(req.Body)
223                 if err != nil {
224                         http.Error(w, "read body failed", http.StatusBadRequest)
225                         return
226                 }
227                 if err := json.Unmarshal(b, request); err != nil {
228                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
229                         return
230                 }
231                 reply, err := rpc.GbpRouteDomainAdd(req.Context(), request)
232                 if err != nil {
233                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
234                         return
235                 }
236                 rep, err := json.MarshalIndent(reply, "", "  ")
237                 if err != nil {
238                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
239                         return
240                 }
241                 w.Write(rep)
242         })
243         mux.HandleFunc("/gbp_route_domain_del", func(w http.ResponseWriter, req *http.Request) {
244                 var request = new(GbpRouteDomainDel)
245                 b, err := ioutil.ReadAll(req.Body)
246                 if err != nil {
247                         http.Error(w, "read body failed", http.StatusBadRequest)
248                         return
249                 }
250                 if err := json.Unmarshal(b, request); err != nil {
251                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
252                         return
253                 }
254                 reply, err := rpc.GbpRouteDomainDel(req.Context(), request)
255                 if err != nil {
256                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
257                         return
258                 }
259                 rep, err := json.MarshalIndent(reply, "", "  ")
260                 if err != nil {
261                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
262                         return
263                 }
264                 w.Write(rep)
265         })
266         mux.HandleFunc("/gbp_subnet_add_del", func(w http.ResponseWriter, req *http.Request) {
267                 var request = new(GbpSubnetAddDel)
268                 b, err := ioutil.ReadAll(req.Body)
269                 if err != nil {
270                         http.Error(w, "read body failed", http.StatusBadRequest)
271                         return
272                 }
273                 if err := json.Unmarshal(b, request); err != nil {
274                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
275                         return
276                 }
277                 reply, err := rpc.GbpSubnetAddDel(req.Context(), request)
278                 if err != nil {
279                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
280                         return
281                 }
282                 rep, err := json.MarshalIndent(reply, "", "  ")
283                 if err != nil {
284                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
285                         return
286                 }
287                 w.Write(rep)
288         })
289         mux.HandleFunc("/gbp_vxlan_tunnel_add", func(w http.ResponseWriter, req *http.Request) {
290                 var request = new(GbpVxlanTunnelAdd)
291                 b, err := ioutil.ReadAll(req.Body)
292                 if err != nil {
293                         http.Error(w, "read body failed", http.StatusBadRequest)
294                         return
295                 }
296                 if err := json.Unmarshal(b, request); err != nil {
297                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
298                         return
299                 }
300                 reply, err := rpc.GbpVxlanTunnelAdd(req.Context(), request)
301                 if err != nil {
302                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
303                         return
304                 }
305                 rep, err := json.MarshalIndent(reply, "", "  ")
306                 if err != nil {
307                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
308                         return
309                 }
310                 w.Write(rep)
311         })
312         mux.HandleFunc("/gbp_vxlan_tunnel_del", func(w http.ResponseWriter, req *http.Request) {
313                 var request = new(GbpVxlanTunnelDel)
314                 b, err := ioutil.ReadAll(req.Body)
315                 if err != nil {
316                         http.Error(w, "read body failed", http.StatusBadRequest)
317                         return
318                 }
319                 if err := json.Unmarshal(b, request); err != nil {
320                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
321                         return
322                 }
323                 reply, err := rpc.GbpVxlanTunnelDel(req.Context(), request)
324                 if err != nil {
325                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
326                         return
327                 }
328                 rep, err := json.MarshalIndent(reply, "", "  ")
329                 if err != nil {
330                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
331                         return
332                 }
333                 w.Write(rep)
334         })
335         return http.HandlerFunc(mux.ServeHTTP)
336 }