@@ -28,11 +28,9 @@ func configEndpoint(connector *Connector, w http.ResponseWriter, r *http.Request
2828 user := connector .ValidateAndReject (w , r )
2929 if user == "" {
3030 return
31- } else if r .Method != "GET" && r .Method != "PATCH" {
32- httpError (w , "Only GET and PATCH are allowed!" , http .StatusMethodNotAllowed )
33- return
3431 }
35- if r .Method == "GET" {
32+ switch r .Method {
33+ case "GET" :
3634 contents , err := os .ReadFile (ConfigJsonPath )
3735 if err != nil {
3836 log .Println ("Error reading " + ConfigJsonPath + " when user accessed /config!" , err )
@@ -42,7 +40,7 @@ func configEndpoint(connector *Connector, w http.ResponseWriter, r *http.Request
4240 connector .Info ("config.view" , "ip" , GetIP (r ), "user" , user )
4341 w .Header ().Set ("content-type" , "application/json" )
4442 _ , _ = w .Write (contents )
45- } else if r . Method == "PATCH" {
43+ case "PATCH" :
4644 var buffer bytes.Buffer
4745 _ , err := buffer .ReadFrom (r .Body )
4846 if err != nil {
@@ -77,6 +75,8 @@ func configEndpoint(connector *Connector, w http.ResponseWriter, r *http.Request
7775 connector .Info ("config.edit" , "ip" , GetIP (r ), "user" , user , "newConfig" , config )
7876 writeJsonStringRes (w , "{\" success\" :true}" )
7977 info .Println ("Config updated remotely by user over HTTP API (see action logs for info)!" )
78+ default :
79+ httpError (w , "Only GET and PATCH are allowed!" , http .StatusMethodNotAllowed )
8080 }
8181}
8282
@@ -156,11 +156,12 @@ func serverEndpoint(connector *Connector, w http.ResponseWriter, r *http.Request
156156 httpError (w , "This server does not exist!" , http .StatusNotFound )
157157 return
158158 }
159- if r .Method == "GET" {
159+ switch r .Method {
160+ case "GET" :
160161 serverEndpointGet (w , process )
161- } else if r . Method == "POST" {
162+ case "POST" :
162163 serverEndpointPost (connector , w , r , process , id , user )
163- } else {
164+ default :
164165 httpError (w , "Only GET and POST is allowed!" , http .StatusMethodNotAllowed )
165166 }
166167}
@@ -211,7 +212,8 @@ func serverEndpointPost(connector *Connector, w http.ResponseWriter, r *http.Req
211212 }
212213 operation := strings .ToUpper (body .String ())
213214 // Check whether the operation is correct or not.
214- if operation == "START" {
215+ switch operation {
216+ case "START" :
215217 // Start process if required.
216218 if process .Online .Load () != 1 {
217219 err = process .StartProcess (connector )
@@ -221,7 +223,7 @@ func serverEndpointPost(connector *Connector, w http.ResponseWriter, r *http.Req
221223 res := make (map [string ]bool )
222224 res ["success" ] = err == nil
223225 writeJsonStructRes (w , res ) // skipcq GSC-G104
224- } else if operation == "STOP" || operation == "KILL" || operation == "TERM" {
226+ case "STOP" , "KILL" , "TERM" :
225227 // Stop process if required.
226228 if process .Online .Load () == 1 {
227229 // Octyne 2.x should drop STOP or move it to SIGTERM.
@@ -237,9 +239,8 @@ func serverEndpointPost(connector *Connector, w http.ResponseWriter, r *http.Req
237239 res := make (map [string ]bool )
238240 res ["success" ] = true
239241 writeJsonStructRes (w , res ) // skipcq GSC-G104
240- } else {
242+ default :
241243 httpError (w , "Invalid operation requested!" , http .StatusBadRequest )
242- return
243244 }
244245}
245246
0 commit comments