From 65464cb62f9853a38d74f8bc310c2f4b7c19e36b Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Fri, 8 Nov 2019 11:42:54 -0500 Subject: Add basic http routing --- backend/main.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 backend/main.go diff --git a/backend/main.go b/backend/main.go new file mode 100644 index 0000000..7b66e00 --- /dev/null +++ b/backend/main.go @@ -0,0 +1,29 @@ +package main + +import "fmt" +import "net/http" + +func RecipeList(w http.ResponseWriter, r *http.Request) { + if r.Method == "GET" { + fmt.Printf("Return all recipe names...\n") + } else if r.Method == "POST" { + } else if r.Method == "DELETE" { + } +} + +func HandleRecipe(w http.ResponseWriter, r *http.Request) { + name := r.URL.Path[len("/recipes/"):] + if r.Method == "GET" { + fmt.Printf("Return recipe \"%s\"...\n", name) + } else if r.Method == "POST" { + fmt.Printf("Create recipe \"%s\"...\n", name) + } else if r.Method == "DELETE" { + fmt.Printf("Delete recipe \"%s\"...\n", name) + } +} + +func main() { + http.HandleFunc("/recipes", RecipeList) + http.HandleFunc("/recipes/", HandleRecipe) + http.ListenAndServe(":8888", nil) +} -- cgit v1.1