Example #1
0
func getContact(w http.ResponseWriter, r *http.Request) {
	if r.Method == "GET"{
		name := r.URL.Query().Get("name")
		c, _ := contact.Get(name)
		json.NewEncoder(w).Encode(c)
	}else{
		w.WriteHeader(http.StatusMethodNotAllowed)
	}
}
Example #2
0
func main() {
	// contact.Save("Hello","1234","*****@*****.**")

	c := contact.Contact{
		Tel:   "123456",
		Email: "[email protected]",
	}

	contact.Add("hello", c)
	fmt.Println(contact.Get("hello"))
}
Example #3
0
func saveContact(w http.ResponseWriter, r *http.Request) {
	var res map[string]string
	json.NewDecoder(r.Body).Decode(&res)
	
	// fmt.Println(res)

	contact.Add(res["name"],contact.Contact{
		Tel		: res["tel"],
		Email	: res["mail"],
	})

	fmt.Println(contact.Get(res["name"]))

}