Skip to content

Instantly share code, notes, and snippets.

@ainar-g
Created June 15, 2018 13:34
Show Gist options
  • Select an option

  • Save ainar-g/f22e418ab56c44bcca3baca929ebc224 to your computer and use it in GitHub Desktop.

Select an option

Save ainar-g/f22e418ab56c44bcca3baca929ebc224 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"net/http"
)
var data map[string][]*int
func main() {
http.HandleFunc("/set", func(w http.ResponseWriter, r *http.Request) {
request_body := struct {
Key *string `json: "key"`
Data []int `json: "data"`
}{}
json.NewDecoder(r.Body).Decode(&request_body)
for _, data_member := range request_body.Data {
data[*request_body.Key] = append(data[*request_body.Key], &data_member)
}
})
http.HandleFunc("/get", func(w http.ResponseWriter, r *http.Request) {
response_data := data[r.URL.Query().Get("key")]
json.NewEncoder(w).Encode(response_data)
})
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment