jagan-parthiban commented on code in PR #7708:
URL: https://github.com/apache/trafficcontrol/pull/7708#discussion_r1305895796


##########
traffic_ops/traffic_ops_golang/parameter/parameters.go:
##########
@@ -364,23 +363,28 @@ func CreateParameter(w http.ResponseWriter, r 
*http.Request) {
 
        // This code block decides if the request body is a slice of parameters 
or a single object.
        var params []tc.ParameterV5
-       switch reflect.TypeOf(data).Kind() {
-       case reflect.Slice:
-               if err := json.Unmarshal(body, &params); err != nil {
-                       api.HandleErr(w, r, tx, http.StatusBadRequest, 
errors.New("error unmarshalling slice"), nil)
-                       return
+
+       // Try to unmarshal the data as a slice
+       var sliceData []map[string]interface{}
+       if err := json.Unmarshal(body, &sliceData); err == nil {
+               for _, item := range sliceData {
+                       param := tc.ParameterV5{
+                               ConfigFile: item["configFile"].(string),
+                               Name:       item["name"].(string),
+                               Secure:     item["secure"].(bool),
+                               Value:      item["value"].(string),
+                       }
+
+                       params = append(params, param)
                }
-       case reflect.Map:
-               // If it is a single object it is still converted to a slice 
for code simplicity.
+       } else {
+               // Try to unmarshal the data as a single object

Review Comment:
   Removed sliceData part



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to