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) } }
func main() { // contact.Save("Hello","1234","*****@*****.**") c := contact.Contact{ Tel: "123456", Email: "[email protected]", } contact.Add("hello", c) fmt.Println(contact.Get("hello")) }
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"])) }