Updated changelog for v0.4.0
[govpp.git] / binapi / l3xc / l3xc_rest.ba.go
1 // Code generated by GoVPP's binapi-generator. DO NOT EDIT.
2
3 package l3xc
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("/l3xc_del", func(w http.ResponseWriter, req *http.Request) {
14                 var request = new(L3xcDel)
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.L3xcDel(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("/l3xc_plugin_get_version", func(w http.ResponseWriter, req *http.Request) {
37                 var request = new(L3xcPluginGetVersion)
38                 reply, err := rpc.L3xcPluginGetVersion(req.Context(), request)
39                 if err != nil {
40                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
41                         return
42                 }
43                 rep, err := json.MarshalIndent(reply, "", "  ")
44                 if err != nil {
45                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
46                         return
47                 }
48                 w.Write(rep)
49         })
50         mux.HandleFunc("/l3xc_update", func(w http.ResponseWriter, req *http.Request) {
51                 var request = new(L3xcUpdate)
52                 b, err := ioutil.ReadAll(req.Body)
53                 if err != nil {
54                         http.Error(w, "read body failed", http.StatusBadRequest)
55                         return
56                 }
57                 if err := json.Unmarshal(b, request); err != nil {
58                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
59                         return
60                 }
61                 reply, err := rpc.L3xcUpdate(req.Context(), request)
62                 if err != nil {
63                         http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
64                         return
65                 }
66                 rep, err := json.MarshalIndent(reply, "", "  ")
67                 if err != nil {
68                         http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
69                         return
70                 }
71                 w.Write(rep)
72         })
73         return http.HandlerFunc(mux.ServeHTTP)
74 }