You can greatly simplify your code by using a proper struct for your JSON unmarshaling:
type Request struct {
URL string `json:"url"`
Params map[string]interface{} `json:"params"`
Type string `json:"type"`
}
Then you can unmarshal it more simply as so:
request := &Request{}
if err := json.Unmarshal([]byte(j), &request); err != nil {
panic(err)
}
And access the values as such:
requestType = request.Type
requestURL = request.URL
for key, value := range request.Params {
switch v := value.(type) {
case float64:
// handle numbers
case string:
// handle strings
}
}
2
solved how to send dynamic json key/value as request params