Generate VPE HTTP handler
[govpp.git] / binapi / vpe / vpe_http.ba.go
1 // Code generated by GoVPP's binapi-generator. DO NOT EDIT.
2
3 package vpe
4
5 import (
6         "encoding/json"
7         "io/ioutil"
8         "net/http"
9 )
10
11 func HTTPHandler(rpc RPCService) http.Handler {
12         mux := http.NewServeMux()
13         mux.HandleFunc("/add_node_next", func(w http.ResponseWriter, req *http.Request) {
14                 var request = new(AddNodeNext)
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.AddNodeNext(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("/cli", func(w http.ResponseWriter, req *http.Request) {
37                 var request = new(Cli)
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.Cli(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("/cli_inband", func(w http.ResponseWriter, req *http.Request) {
60                 var request = new(CliInband)
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.CliInband(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("/control_ping", func(w http.ResponseWriter, req *http.Request) {
83                 var request = new(ControlPing)
84                 reply, err := rpc.ControlPing(req.Context(), request)
85                 if err != nil {
86                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
87                         return
88                 }
89                 rep, err := json.MarshalIndent(reply, "", "  ")
90                 if err != nil {
91                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
92                         return
93                 }
94                 w.Write(rep)
95         })
96         mux.HandleFunc("/get_f64_endian_value", func(w http.ResponseWriter, req *http.Request) {
97                 var request = new(GetF64EndianValue)
98                 b, err := ioutil.ReadAll(req.Body)
99                 if err != nil {
100                         http.Error(w, "read body failed", http.StatusBadRequest)
101                         return
102                 }
103                 if err := json.Unmarshal(b, request); err != nil {
104                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
105                         return
106                 }
107                 reply, err := rpc.GetF64EndianValue(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("/get_f64_increment_by_one", func(w http.ResponseWriter, req *http.Request) {
120                 var request = new(GetF64IncrementByOne)
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.GetF64IncrementByOne(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("/get_next_index", func(w http.ResponseWriter, req *http.Request) {
143                 var request = new(GetNextIndex)
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.GetNextIndex(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("/get_node_graph", func(w http.ResponseWriter, req *http.Request) {
166                 var request = new(GetNodeGraph)
167                 reply, err := rpc.GetNodeGraph(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("/get_node_index", func(w http.ResponseWriter, req *http.Request) {
180                 var request = new(GetNodeIndex)
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.GetNodeIndex(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("/show_threads", func(w http.ResponseWriter, req *http.Request) {
203                 var request = new(ShowThreads)
204                 reply, err := rpc.ShowThreads(req.Context(), request)
205                 if err != nil {
206                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
207                         return
208                 }
209                 rep, err := json.MarshalIndent(reply, "", "  ")
210                 if err != nil {
211                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
212                         return
213                 }
214                 w.Write(rep)
215         })
216         mux.HandleFunc("/show_version", func(w http.ResponseWriter, req *http.Request) {
217                 var request = new(ShowVersion)
218                 reply, err := rpc.ShowVersion(req.Context(), request)
219                 if err != nil {
220                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
221                         return
222                 }
223                 rep, err := json.MarshalIndent(reply, "", "  ")
224                 if err != nil {
225                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
226                         return
227                 }
228                 w.Write(rep)
229         })
230         mux.HandleFunc("/show_vpe_system_time", func(w http.ResponseWriter, req *http.Request) {
231                 var request = new(ShowVpeSystemTime)
232                 reply, err := rpc.ShowVpeSystemTime(req.Context(), request)
233                 if err != nil {
234                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
235                         return
236                 }
237                 rep, err := json.MarshalIndent(reply, "", "  ")
238                 if err != nil {
239                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
240                         return
241                 }
242                 w.Write(rep)
243         })
244         return http.HandlerFunc(mux.ServeHTTP)
245 }