Exemplo n.º 1
0
func handleProfile(service api.Service) {
	makeHandler("/profile", func(w http.ResponseWriter, r *http.Request) {
		switch r.Method {
		case "POST":
			input := api.UserInput{}
			decoder.Decode(&input, r.Form)

			_, err := service.PutUser(input.Email, input)
			if err != nil {
				fmt.Printf("%s\n", err)
				return
			}

			http.Redirect(w, r, "/order.html", http.StatusFound)
		case "DELETE":
			if err := service.RemoveUser(r.Form["email"][0]); err != nil {
				fmt.Printf("%s\n", err)
				return
			}
		}
	})
}