Improve binapi generator
[govpp.git] / binapi / bfd / bfd_rest.ba.go
1 // Code generated by GoVPP's binapi-generator. DO NOT EDIT.
2
3 package bfd
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("/bfd_auth_del_key", func(w http.ResponseWriter, req *http.Request) {
14                 var request = new(BfdAuthDelKey)
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.BfdAuthDelKey(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("/bfd_auth_set_key", func(w http.ResponseWriter, req *http.Request) {
37                 var request = new(BfdAuthSetKey)
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.BfdAuthSetKey(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("/bfd_udp_add", func(w http.ResponseWriter, req *http.Request) {
60                 var request = new(BfdUDPAdd)
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.BfdUDPAdd(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("/bfd_udp_auth_activate", func(w http.ResponseWriter, req *http.Request) {
83                 var request = new(BfdUDPAuthActivate)
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.BfdUDPAuthActivate(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("/bfd_udp_auth_deactivate", func(w http.ResponseWriter, req *http.Request) {
106                 var request = new(BfdUDPAuthDeactivate)
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.BfdUDPAuthDeactivate(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("/bfd_udp_del", func(w http.ResponseWriter, req *http.Request) {
129                 var request = new(BfdUDPDel)
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.BfdUDPDel(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("/bfd_udp_del_echo_source", func(w http.ResponseWriter, req *http.Request) {
152                 var request = new(BfdUDPDelEchoSource)
153                 reply, err := rpc.BfdUDPDelEchoSource(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("/bfd_udp_get_echo_source", func(w http.ResponseWriter, req *http.Request) {
166                 var request = new(BfdUDPGetEchoSource)
167                 reply, err := rpc.BfdUDPGetEchoSource(req.Context(), request)
168                 if err != nil {
169                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
170                         return
171                 }
172                 rep, err := json.MarshalIndent(reply, "", "  ")
173                 if err != nil {
174                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
175                         return
176                 }
177                 w.Write(rep)
178         })
179         mux.HandleFunc("/bfd_udp_mod", func(w http.ResponseWriter, req *http.Request) {
180                 var request = new(BfdUDPMod)
181                 b, err := ioutil.ReadAll(req.Body)
182                 if err != nil {
183                         http.Error(w, "read body failed", http.StatusBadRequest)
184                         return
185                 }
186                 if err := json.Unmarshal(b, request); err != nil {
187                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
188                         return
189                 }
190                 reply, err := rpc.BfdUDPMod(req.Context(), request)
191                 if err != nil {
192                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
193                         return
194                 }
195                 rep, err := json.MarshalIndent(reply, "", "  ")
196                 if err != nil {
197                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
198                         return
199                 }
200                 w.Write(rep)
201         })
202         mux.HandleFunc("/bfd_udp_session_set_flags", func(w http.ResponseWriter, req *http.Request) {
203                 var request = new(BfdUDPSessionSetFlags)
204                 b, err := ioutil.ReadAll(req.Body)
205                 if err != nil {
206                         http.Error(w, "read body failed", http.StatusBadRequest)
207                         return
208                 }
209                 if err := json.Unmarshal(b, request); err != nil {
210                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
211                         return
212                 }
213                 reply, err := rpc.BfdUDPSessionSetFlags(req.Context(), request)
214                 if err != nil {
215                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
216                         return
217                 }
218                 rep, err := json.MarshalIndent(reply, "", "  ")
219                 if err != nil {
220                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
221                         return
222                 }
223                 w.Write(rep)
224         })
225         mux.HandleFunc("/bfd_udp_set_echo_source", func(w http.ResponseWriter, req *http.Request) {
226                 var request = new(BfdUDPSetEchoSource)
227                 b, err := ioutil.ReadAll(req.Body)
228                 if err != nil {
229                         http.Error(w, "read body failed", http.StatusBadRequest)
230                         return
231                 }
232                 if err := json.Unmarshal(b, request); err != nil {
233                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
234                         return
235                 }
236                 reply, err := rpc.BfdUDPSetEchoSource(req.Context(), request)
237                 if err != nil {
238                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
239                         return
240                 }
241                 rep, err := json.MarshalIndent(reply, "", "  ")
242                 if err != nil {
243                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
244                         return
245                 }
246                 w.Write(rep)
247         })
248         mux.HandleFunc("/want_bfd_events", func(w http.ResponseWriter, req *http.Request) {
249                 var request = new(WantBfdEvents)
250                 b, err := ioutil.ReadAll(req.Body)
251                 if err != nil {
252                         http.Error(w, "read body failed", http.StatusBadRequest)
253                         return
254                 }
255                 if err := json.Unmarshal(b, request); err != nil {
256                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
257                         return
258                 }
259                 reply, err := rpc.WantBfdEvents(req.Context(), request)
260                 if err != nil {
261                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
262                         return
263                 }
264                 rep, err := json.MarshalIndent(reply, "", "  ")
265                 if err != nil {
266                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
267                         return
268                 }
269                 w.Write(rep)
270         })
271         return http.HandlerFunc(mux.ServeHTTP)
272 }