@@ -81,6 +81,8 @@ func (api *NodeApi) show(w http.ResponseWriter, req *http.Request) {
8181
8282// change the logging state for one node
8383func (api * NodeApi ) put (w http.ResponseWriter , req * http.Request ) {
84+ var resp []byte
85+ var err error
8486 vars := mux .Vars (req )
8587 plog .Debug (fmt .Sprintf ("Receive %s request %s %v from %s." , req .Method , req .URL .Path , vars , req .RemoteAddr ))
8688 if _ , ok := req .URL .Query ()["state" ]; ! ok {
@@ -90,10 +92,14 @@ func (api *NodeApi) put(w http.ResponseWriter, req *http.Request) {
9092 state := req .URL .Query ()["state" ][0 ]
9193 nodes := make ([]string , 0 , 1 )
9294 nodes = append (nodes , vars ["node" ])
93- nodeManager .SetConsoleState (nodes , state )
9495 plog .InfoNode (vars ["node" ], fmt .Sprintf ("The console state has been changed to %s." , state ))
96+ result := nodeManager .SetConsoleState (nodes , state )
97+ if resp , err = json .Marshal (result ); err != nil {
98+ plog .HandleHttp (w , req , http .StatusInternalServerError , err .Error ())
99+ return
100+ }
95101 w .Header ().Set ("Content-Type" , "application/json; charset=UTF-8" )
96- w . WriteHeader ( http . StatusAccepted )
102+ fmt . Fprintf ( w , "%s \n " , resp )
97103}
98104
99105// change the logging state for nodes
@@ -107,7 +113,7 @@ func (api *NodeApi) bulkPut(w http.ResponseWriter, req *http.Request) {
107113 return
108114 }
109115 state := req .URL .Query ()["state" ][0 ]
110- storNodes := make ( map [string ][]storage.Node , 0 )
116+ var storNodes map [string ][]storage.Node
111117 body , err := ioutil .ReadAll (req .Body )
112118 if err != nil {
113119 plog .HandleHttp (w , req , http .StatusInternalServerError , err .Error ())
@@ -137,7 +143,7 @@ func (api *NodeApi) bulkPut(w http.ResponseWriter, req *http.Request) {
137143
138144func (api * NodeApi ) post (w http.ResponseWriter , req * http.Request ) {
139145 plog .Debug (fmt .Sprintf ("Receive %s request %s from %s." , req .Method , req .URL .Path , req .RemoteAddr ))
140- node := storage .NewNode ()
146+ var node storage.Node
141147 body , err := ioutil .ReadAll (req .Body )
142148 if err != nil {
143149 plog .HandleHttp (w , req , http .StatusInternalServerError , err .Error ())
@@ -147,7 +153,7 @@ func (api *NodeApi) post(w http.ResponseWriter, req *http.Request) {
147153 plog .HandleHttp (w , req , http .StatusInternalServerError , err .Error ())
148154 return
149155 }
150- if err := json .Unmarshal (body , node ); err != nil {
156+ if err := json .Unmarshal (body , & node ); err != nil {
151157 plog .HandleHttp (w , req , http .StatusUnprocessableEntity , err .Error ())
152158 return
153159 }
@@ -159,7 +165,7 @@ func (api *NodeApi) post(w http.ResponseWriter, req *http.Request) {
159165 plog .HandleHttp (w , req , http .StatusBadRequest , "Driver is not defined" )
160166 return
161167 }
162- httpcode , msg := nodeManager .PostNode (node )
168+ httpcode , msg := nodeManager .PostNode (& node )
163169 if httpcode >= 400 {
164170 plog .HandleHttp (w , req , httpcode , msg )
165171 return
@@ -171,7 +177,7 @@ func (api *NodeApi) post(w http.ResponseWriter, req *http.Request) {
171177func (api * NodeApi ) bulkPost (w http.ResponseWriter , req * http.Request ) {
172178 plog .Debug (fmt .Sprintf ("Receive %s request %s from %s." , req .Method , req .URL .Path , req .RemoteAddr ))
173179 var resp []byte
174- nodes := make ( map [string ][]storage.Node )
180+ var nodes map [string ][]storage.Node
175181 body , err := ioutil .ReadAll (req .Body )
176182 if err != nil {
177183 plog .HandleHttp (w , req , http .StatusInternalServerError , err .Error ())
0 commit comments