Beispiel #1
0
func get(rw http.ResponseWriter, req *http.Request, p httprouter.Params) {

	key := p.ByName("id")
	key_int, _ := strconv.Atoi(key)
	var port []string
	var response Response
	port = strings.Split(req.Host, ":")
	if port[1] == "3000" {
		response.Key = key_int
		response.Value = server_1[key_int]

	} else if port[1] == "3001" {
		response.Key = key_int
		response.Value = server_2[key_int]

	} else {
		response.Key = key_int
		response.Value = server_3[key_int]

	}
	resp, err := json.Marshal(response)
	if err != nil {
		http.Error(rw, "Error in server", http.StatusInternalServerError)
		return
	}
	rw.Header().Set("Content-Type", "application/json")
	rw.Write(resp)
}
Beispiel #2
0
func put(rw http.ResponseWriter, req *http.Request, p httprouter.Params) {

	key := p.ByName("id")
	value := p.ByName("value")
	var port []string
	key_int, _ := strconv.Atoi(key)

	port = strings.Split(req.Host, ":")
	if port[1] == "3000" {
		server_1[key_int] = value

	} else if port[1] == "3001" {
		server_2[key_int] = value

	} else {
		server_3[key_int] = value

	}

}