Improve binapi generator
[govpp.git] / binapi / ikev2 / ikev2_rest.ba.go
1 // Code generated by GoVPP's binapi-generator. DO NOT EDIT.
2
3 package ikev2
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("/ikev2_initiate_del_child_sa", func(w http.ResponseWriter, req *http.Request) {
14                 var request = new(Ikev2InitiateDelChildSa)
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.Ikev2InitiateDelChildSa(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("/ikev2_initiate_del_ike_sa", func(w http.ResponseWriter, req *http.Request) {
37                 var request = new(Ikev2InitiateDelIkeSa)
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.Ikev2InitiateDelIkeSa(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("/ikev2_initiate_rekey_child_sa", func(w http.ResponseWriter, req *http.Request) {
60                 var request = new(Ikev2InitiateRekeyChildSa)
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.Ikev2InitiateRekeyChildSa(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("/ikev2_initiate_sa_init", func(w http.ResponseWriter, req *http.Request) {
83                 var request = new(Ikev2InitiateSaInit)
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.Ikev2InitiateSaInit(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("/ikev2_plugin_get_version", func(w http.ResponseWriter, req *http.Request) {
106                 var request = new(Ikev2PluginGetVersion)
107                 reply, err := rpc.Ikev2PluginGetVersion(req.Context(), request)
108                 if err != nil {
109                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
110                         return
111                 }
112                 rep, err := json.MarshalIndent(reply, "", "  ")
113                 if err != nil {
114                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
115                         return
116                 }
117                 w.Write(rep)
118         })
119         mux.HandleFunc("/ikev2_profile_add_del", func(w http.ResponseWriter, req *http.Request) {
120                 var request = new(Ikev2ProfileAddDel)
121                 b, err := ioutil.ReadAll(req.Body)
122                 if err != nil {
123                         http.Error(w, "read body failed", http.StatusBadRequest)
124                         return
125                 }
126                 if err := json.Unmarshal(b, request); err != nil {
127                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
128                         return
129                 }
130                 reply, err := rpc.Ikev2ProfileAddDel(req.Context(), request)
131                 if err != nil {
132                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
133                         return
134                 }
135                 rep, err := json.MarshalIndent(reply, "", "  ")
136                 if err != nil {
137                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
138                         return
139                 }
140                 w.Write(rep)
141         })
142         mux.HandleFunc("/ikev2_profile_set_auth", func(w http.ResponseWriter, req *http.Request) {
143                 var request = new(Ikev2ProfileSetAuth)
144                 b, err := ioutil.ReadAll(req.Body)
145                 if err != nil {
146                         http.Error(w, "read body failed", http.StatusBadRequest)
147                         return
148                 }
149                 if err := json.Unmarshal(b, request); err != nil {
150                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
151                         return
152                 }
153                 reply, err := rpc.Ikev2ProfileSetAuth(req.Context(), request)
154                 if err != nil {
155                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
156                         return
157                 }
158                 rep, err := json.MarshalIndent(reply, "", "  ")
159                 if err != nil {
160                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
161                         return
162                 }
163                 w.Write(rep)
164         })
165         mux.HandleFunc("/ikev2_profile_set_id", func(w http.ResponseWriter, req *http.Request) {
166                 var request = new(Ikev2ProfileSetID)
167                 b, err := ioutil.ReadAll(req.Body)
168                 if err != nil {
169                         http.Error(w, "read body failed", http.StatusBadRequest)
170                         return
171                 }
172                 if err := json.Unmarshal(b, request); err != nil {
173                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
174                         return
175                 }
176                 reply, err := rpc.Ikev2ProfileSetID(req.Context(), request)
177                 if err != nil {
178                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
179                         return
180                 }
181                 rep, err := json.MarshalIndent(reply, "", "  ")
182                 if err != nil {
183                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
184                         return
185                 }
186                 w.Write(rep)
187         })
188         mux.HandleFunc("/ikev2_profile_set_ipsec_udp_port", func(w http.ResponseWriter, req *http.Request) {
189                 var request = new(Ikev2ProfileSetIpsecUDPPort)
190                 b, err := ioutil.ReadAll(req.Body)
191                 if err != nil {
192                         http.Error(w, "read body failed", http.StatusBadRequest)
193                         return
194                 }
195                 if err := json.Unmarshal(b, request); err != nil {
196                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
197                         return
198                 }
199                 reply, err := rpc.Ikev2ProfileSetIpsecUDPPort(req.Context(), request)
200                 if err != nil {
201                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
202                         return
203                 }
204                 rep, err := json.MarshalIndent(reply, "", "  ")
205                 if err != nil {
206                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
207                         return
208                 }
209                 w.Write(rep)
210         })
211         mux.HandleFunc("/ikev2_profile_set_liveness", func(w http.ResponseWriter, req *http.Request) {
212                 var request = new(Ikev2ProfileSetLiveness)
213                 b, err := ioutil.ReadAll(req.Body)
214                 if err != nil {
215                         http.Error(w, "read body failed", http.StatusBadRequest)
216                         return
217                 }
218                 if err := json.Unmarshal(b, request); err != nil {
219                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
220                         return
221                 }
222                 reply, err := rpc.Ikev2ProfileSetLiveness(req.Context(), request)
223                 if err != nil {
224                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
225                         return
226                 }
227                 rep, err := json.MarshalIndent(reply, "", "  ")
228                 if err != nil {
229                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
230                         return
231                 }
232                 w.Write(rep)
233         })
234         mux.HandleFunc("/ikev2_profile_set_ts", func(w http.ResponseWriter, req *http.Request) {
235                 var request = new(Ikev2ProfileSetTs)
236                 b, err := ioutil.ReadAll(req.Body)
237                 if err != nil {
238                         http.Error(w, "read body failed", http.StatusBadRequest)
239                         return
240                 }
241                 if err := json.Unmarshal(b, request); err != nil {
242                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
243                         return
244                 }
245                 reply, err := rpc.Ikev2ProfileSetTs(req.Context(), request)
246                 if err != nil {
247                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
248                         return
249                 }
250                 rep, err := json.MarshalIndent(reply, "", "  ")
251                 if err != nil {
252                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
253                         return
254                 }
255                 w.Write(rep)
256         })
257         mux.HandleFunc("/ikev2_profile_set_udp_encap", func(w http.ResponseWriter, req *http.Request) {
258                 var request = new(Ikev2ProfileSetUDPEncap)
259                 b, err := ioutil.ReadAll(req.Body)
260                 if err != nil {
261                         http.Error(w, "read body failed", http.StatusBadRequest)
262                         return
263                 }
264                 if err := json.Unmarshal(b, request); err != nil {
265                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
266                         return
267                 }
268                 reply, err := rpc.Ikev2ProfileSetUDPEncap(req.Context(), request)
269                 if err != nil {
270                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
271                         return
272                 }
273                 rep, err := json.MarshalIndent(reply, "", "  ")
274                 if err != nil {
275                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
276                         return
277                 }
278                 w.Write(rep)
279         })
280         mux.HandleFunc("/ikev2_set_esp_transforms", func(w http.ResponseWriter, req *http.Request) {
281                 var request = new(Ikev2SetEspTransforms)
282                 b, err := ioutil.ReadAll(req.Body)
283                 if err != nil {
284                         http.Error(w, "read body failed", http.StatusBadRequest)
285                         return
286                 }
287                 if err := json.Unmarshal(b, request); err != nil {
288                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
289                         return
290                 }
291                 reply, err := rpc.Ikev2SetEspTransforms(req.Context(), request)
292                 if err != nil {
293                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
294                         return
295                 }
296                 rep, err := json.MarshalIndent(reply, "", "  ")
297                 if err != nil {
298                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
299                         return
300                 }
301                 w.Write(rep)
302         })
303         mux.HandleFunc("/ikev2_set_ike_transforms", func(w http.ResponseWriter, req *http.Request) {
304                 var request = new(Ikev2SetIkeTransforms)
305                 b, err := ioutil.ReadAll(req.Body)
306                 if err != nil {
307                         http.Error(w, "read body failed", http.StatusBadRequest)
308                         return
309                 }
310                 if err := json.Unmarshal(b, request); err != nil {
311                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
312                         return
313                 }
314                 reply, err := rpc.Ikev2SetIkeTransforms(req.Context(), request)
315                 if err != nil {
316                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
317                         return
318                 }
319                 rep, err := json.MarshalIndent(reply, "", "  ")
320                 if err != nil {
321                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
322                         return
323                 }
324                 w.Write(rep)
325         })
326         mux.HandleFunc("/ikev2_set_local_key", func(w http.ResponseWriter, req *http.Request) {
327                 var request = new(Ikev2SetLocalKey)
328                 b, err := ioutil.ReadAll(req.Body)
329                 if err != nil {
330                         http.Error(w, "read body failed", http.StatusBadRequest)
331                         return
332                 }
333                 if err := json.Unmarshal(b, request); err != nil {
334                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
335                         return
336                 }
337                 reply, err := rpc.Ikev2SetLocalKey(req.Context(), request)
338                 if err != nil {
339                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
340                         return
341                 }
342                 rep, err := json.MarshalIndent(reply, "", "  ")
343                 if err != nil {
344                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
345                         return
346                 }
347                 w.Write(rep)
348         })
349         mux.HandleFunc("/ikev2_set_responder", func(w http.ResponseWriter, req *http.Request) {
350                 var request = new(Ikev2SetResponder)
351                 b, err := ioutil.ReadAll(req.Body)
352                 if err != nil {
353                         http.Error(w, "read body failed", http.StatusBadRequest)
354                         return
355                 }
356                 if err := json.Unmarshal(b, request); err != nil {
357                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
358                         return
359                 }
360                 reply, err := rpc.Ikev2SetResponder(req.Context(), request)
361                 if err != nil {
362                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
363                         return
364                 }
365                 rep, err := json.MarshalIndent(reply, "", "  ")
366                 if err != nil {
367                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
368                         return
369                 }
370                 w.Write(rep)
371         })
372         mux.HandleFunc("/ikev2_set_sa_lifetime", func(w http.ResponseWriter, req *http.Request) {
373                 var request = new(Ikev2SetSaLifetime)
374                 b, err := ioutil.ReadAll(req.Body)
375                 if err != nil {
376                         http.Error(w, "read body failed", http.StatusBadRequest)
377                         return
378                 }
379                 if err := json.Unmarshal(b, request); err != nil {
380                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
381                         return
382                 }
383                 reply, err := rpc.Ikev2SetSaLifetime(req.Context(), request)
384                 if err != nil {
385                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
386                         return
387                 }
388                 rep, err := json.MarshalIndent(reply, "", "  ")
389                 if err != nil {
390                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
391                         return
392                 }
393                 w.Write(rep)
394         })
395         mux.HandleFunc("/ikev2_set_tunnel_interface", func(w http.ResponseWriter, req *http.Request) {
396                 var request = new(Ikev2SetTunnelInterface)
397                 b, err := ioutil.ReadAll(req.Body)
398                 if err != nil {
399                         http.Error(w, "read body failed", http.StatusBadRequest)
400                         return
401                 }
402                 if err := json.Unmarshal(b, request); err != nil {
403                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
404                         return
405                 }
406                 reply, err := rpc.Ikev2SetTunnelInterface(req.Context(), request)
407                 if err != nil {
408                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
409                         return
410                 }
411                 rep, err := json.MarshalIndent(reply, "", "  ")
412                 if err != nil {
413                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
414                         return
415                 }
416                 w.Write(rep)
417         })
418         return http.HandlerFunc(mux.ServeHTTP)
419 }