func createRestaurant() { u, err := db.UserByEmail("*****@*****.**") if err != nil { panic(err) } r := db.Restaurant{} r.Name = "Peacock India Restaurants" b := make([]byte, 16) f, err := os.Open("/dev/urandom") if err != nil { panic(err) } f.Read(b) r.Key = fmt.Sprintf("%x%x%x%x%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:]) r.About = "Authentic South Indian Restaurant" r.AdminIds = []bson.ObjectId{u.Id} branch := db.RestaurantBranch{} branch.Name = "Peacock Fremont" branch.Address = "2342 Walnut Ave" branch.City = "Fremont" branch.State = "CA" branch.Zipcode = "94582" r.Branches = []db.RestaurantBranch{branch} fmt.Println("Restaurant created", r.Create() == nil) }
func hello(w http.ResponseWriter, r *http.Request) { u, err := db.UserByEmail("*****@*****.**") if err != nil { log.Fatal(err) } buf, _ := json.Marshal(u) w.Write(buf) }
func user(w http.ResponseWriter, r *http.Request) { email := r.URL.Path[len("/user/"):] u, err := db.UserByEmail(email) if err != nil { w.WriteHeader(http.StatusInternalServerError) } else { buf, _ := json.Marshal(u) w.Write(buf) } }