コード例 #1
0
func PutKeyPair(rw http.ResponseWriter, req *http.Request, p httprouter.Params) {
	var newPair structure.KeyValuePair
	key := convert(p.ByName("key"))
	value := p.ByName("value")

	newPair.Key = key
	newPair.Value = value
	pairMap[key] = newPair
	result, _ := json.Marshal(newPair)

	rw.Header().Set("Content-Type", "application/json")
	rw.WriteHeader(201)
	fmt.Fprintf(rw, "%s", result)
}
コード例 #2
0
func GetKeyPair(rw http.ResponseWriter, req *http.Request, p httprouter.Params) {
	inputKey := convert(p.ByName("key"))
	//fmt.Println(inputKey)
	var findPair structure.KeyValuePair
	for key, value := range pairMap {
		if key == inputKey {
			findPair.Key = inputKey
			findPair.Value = value.Value
		}
	}
	result, _ := json.Marshal(findPair)

	rw.Header().Set("Content-Type", "application/json")
	rw.WriteHeader(201)
	fmt.Fprintf(rw, "%s", result)
}