Hi all
I’m trying to send a POST request via a PUT method to input data into a key-value store… if there’s a better way, then let me know!
So the PUT method is to update the key/value pairing… and so i delete the key/value and then insert a new key/value which takes its place…
see code below:
case urv.Get("key") != "" && urv.Get("value") != "" && urv.Get("newvalue") != "": //edit the value in that key.
toremove := false
for i, v := range data[urv.Get("key")] {
if v == urv.Get("value") {
toremove = true
if toremove == true {
if len(data[urv.Get("key")])-1 == i {
data[urv.Get("key")] = data[urv.Get("key")][:i]
} else {
data[urv.Get("key")] = append(data[urv.Get("key")][:i], data[urv.Get("key")][i+1:]...)
}
break
}
}
}
if !toremove {
fmt.Fprintf(w, "Value: %v doesn't exist in the data store", urv.Get("value"))
return
}
data[urv.Get("key")] = append(data[urv.Get("key")], urv.Get("newvalue"))
The above all works… however instead of data[urv.Get("key")] = append(data[urv.Get("key")], urv.Get("newvalue"))
I want to use the http.POST or http.NewRequest methods to send a POST request using a link, to input this data…
I have the user input data like the below
http://localhost:8080/&key=key&value=value&datatype=datatype
the above is pretty self explanatory, it will insert data into the map with the key, value and datatype defined in the URL…
The reason for me needing to use the POST request, is to allow my users to select the datatype they want to store it as…
I was thinking something like
http.NewRequest("POST", "http://localhost:8080/?key="+urv.Get("key")+"?values="+urv.Get("value")+"?datatype="+urv.Get("datatype")
the urv.Get function will get the specific param from the URL.
Thank you