Updated changelog for v0.4.0
[govpp.git] / binapi / ipfix_export / ipfix_export_rest.ba.go
1 // Code generated by GoVPP's binapi-generator. DO NOT EDIT.
2
3 package ipfix_export
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("/ipfix_classify_table_add_del", func(w http.ResponseWriter, req *http.Request) {
14                 var request = new(IpfixClassifyTableAddDel)
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.IpfixClassifyTableAddDel(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("/ipfix_flush", func(w http.ResponseWriter, req *http.Request) {
37                 var request = new(IpfixFlush)
38                 reply, err := rpc.IpfixFlush(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("/set_ipfix_classify_stream", func(w http.ResponseWriter, req *http.Request) {
51                 var request = new(SetIpfixClassifyStream)
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.SetIpfixClassifyStream(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         mux.HandleFunc("/set_ipfix_exporter", func(w http.ResponseWriter, req *http.Request) {
74                 var request = new(SetIpfixExporter)
75                 b, err := ioutil.ReadAll(req.Body)
76                 if err != nil {
77                         http.Error(w, "read body failed", http.StatusBadRequest)
78                         return
79                 }
80                 if err := json.Unmarshal(b, request); err != nil {
81                         http.Error(w, "unmarshal data failed", http.StatusBadRequest)
82                         return
83                 }
84                 reply, err := rpc.SetIpfixExporter(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         return http.HandlerFunc(mux.ServeHTTP)
97 }