Updated changelog for v0.4.0
[govpp.git] / binapi / map / map_rest.ba.go
1 // Code generated by GoVPP's binapi-generator. DO NOT EDIT.
2
3 package maps
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("/map_add_del_rule", func(w http.ResponseWriter, req *http.Request) {
14                 var request = new(MapAddDelRule)
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.MapAddDelRule(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("/map_add_domain", func(w http.ResponseWriter, req *http.Request) {
37                 var request = new(MapAddDomain)
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.MapAddDomain(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("/map_del_domain", func(w http.ResponseWriter, req *http.Request) {
60                 var request = new(MapDelDomain)
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.MapDelDomain(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("/map_if_enable_disable", func(w http.ResponseWriter, req *http.Request) {
83                 var request = new(MapIfEnableDisable)
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.MapIfEnableDisable(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("/map_param_add_del_pre_resolve", func(w http.ResponseWriter, req *http.Request) {
106                 var request = new(MapParamAddDelPreResolve)
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.MapParamAddDelPreResolve(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("/map_param_get", func(w http.ResponseWriter, req *http.Request) {
129                 var request = new(MapParamGet)
130                 reply, err := rpc.MapParamGet(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("/map_param_set_fragmentation", func(w http.ResponseWriter, req *http.Request) {
143                 var request = new(MapParamSetFragmentation)
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.MapParamSetFragmentation(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("/map_param_set_icmp", func(w http.ResponseWriter, req *http.Request) {
166                 var request = new(MapParamSetICMP)
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.MapParamSetICMP(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("/map_param_set_icmp6", func(w http.ResponseWriter, req *http.Request) {
189                 var request = new(MapParamSetICMP6)
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.MapParamSetICMP6(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("/map_param_set_security_check", func(w http.ResponseWriter, req *http.Request) {
212                 var request = new(MapParamSetSecurityCheck)
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.MapParamSetSecurityCheck(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("/map_param_set_tcp", func(w http.ResponseWriter, req *http.Request) {
235                 var request = new(MapParamSetTCP)
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.MapParamSetTCP(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("/map_param_set_traffic_class", func(w http.ResponseWriter, req *http.Request) {
258                 var request = new(MapParamSetTrafficClass)
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.MapParamSetTrafficClass(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("/map_summary_stats", func(w http.ResponseWriter, req *http.Request) {
281                 var request = new(MapSummaryStats)
282                 reply, err := rpc.MapSummaryStats(req.Context(), request)
283                 if err != nil {
284                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
285                         return
286                 }
287                 rep, err := json.MarshalIndent(reply, "", "  ")
288                 if err != nil {
289                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
290                         return
291                 }
292                 w.Write(rep)
293         })
294         return http.HandlerFunc(mux.ServeHTTP)
295 }