コード例 #1
0
func colorController(w http.ResponseWriter, r *http.Request) {
	color := mux.Vars(r)["color"]

	responseMessage := colorResponse{"Color successfully activated", color}

	message, error := GenerateResponseMessage(responseMessage)

	if error != nil {
		fmt.Fprintf(w, "There was an error")

		return
	}

	fmt.Fprintf(w, message)

	switch color {
	case "red":
		dioder.SetAll(255, 0, 0)
		break
	case "green":
		dioder.SetAll(0, 255, 0)
		break
	case "blue":
		dioder.SetAll(0, 0, 255)
		break
	}
}
コード例 #2
0
func controlController(w http.ResponseWriter, r *http.Request) {
	state := mux.Vars(r)["state"]

	if state == "off" {
		dioder.SetAll(0, 0, 0)
	}
}