todo.go 706 B

1234567891011121314151617181920212223242526272829303132333435
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "net/http"
  6. "github.com/gorilla/mux"
  7. "rate-it-api/models"
  8. )
  9. func TodoIndex(w http.ResponseWriter, r *http.Request) {
  10. todos := models.Todos{
  11. models.Todo{Name: "Write presentation"},
  12. models.Todo{Name: "Host meetup"},
  13. }
  14. w.Header().Set("Content-Type", "application/json; charset=UTF-8")
  15. w.WriteHeader(http.StatusOK)
  16. if err := json.NewEncoder(w).Encode(todos); err != nil {
  17. panic(err)
  18. }
  19. }
  20. var Test = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  21. fmt.Fprintln(w, "Test:")
  22. })
  23. func TodoShow(w http.ResponseWriter, r *http.Request) {
  24. vars := mux.Vars(r)
  25. todoId := vars["todoId"]
  26. fmt.Fprintln(w, "Todo show:", todoId)
  27. }