Beispiel #1
0
func UpdateGadget(w http.ResponseWriter, req *http.Request) {
	args := GetArgs(req)
	var g quimby.Gadget
	dec := json.NewDecoder(req.Body)
	err := dec.Decode(&g)
	if err != nil {
		context.Set(req, "error", err)
		return // err
	}

	g.DB = args.DB
	g.Id = args.Vars["id"]
	err = g.Save()
	if err != nil {
		context.Set(req, "error", err)
		return // err
	}

	u, err := url.Parse(fmt.Sprintf("/api/gadgets/%s", g.Id))
	if err != nil {
		context.Set(req, "error", err)
		return //err
	}
	w.Header().Set("Location", u.String())
}
Beispiel #2
0
func AddGadget(g *quimby.Gadget) {
	if g.Name == "" {
		fmt.Print("name: ")
		fmt.Scanf("%s\n", &g.Name)
		fmt.Print("host: ")
		fmt.Scanf("%s\n", &g.Host)
		fmt.Print(fmt.Sprintf("really save gadget (name: %s, host: %s)? (Y/n) ", g.Name, g.Host))
		var save string
		fmt.Scanf("%s\n", &save)
		if save == "y" || save == "Y" || save == "" {
			fmt.Println(g.Save())
		} else {
			fmt.Println("not saving")
		}
	} else {
		err := g.Save()
		if err != nil {
			log.Fatal(err)
		}
	}
	fmt.Println(g.Id)
}
Beispiel #3
0
		}))

		var err error
		dir, err = ioutil.TempDir("", "")
		pth = path.Join(dir, "db")
		Expect(err).To(BeNil())

		db, err = quimby.GetDB(pth)
		Expect(err).To(BeNil())

		g = &quimby.Gadget{
			Name: "lights",
			Host: ts.URL,
			DB:   db,
		}
		err = g.Save()
		Expect(err).To(BeNil())
	})

	AfterEach(func() {
		db.Close()
		os.RemoveAll(dir)
		ts.Close()
	})

	It("can save", func() {
		g2 := &quimby.Gadget{
			Id:   g.Id,
			Name: "lights",
			DB:   db,
		}