1234567891011121314151617181920212223242526272829303132333435 |
- package controllers
- import (
- "encoding/json"
- "fmt"
- "net/http"
- "github.com/gorilla/mux"
- "rate-it-api/models"
- )
- func TodoIndex(w http.ResponseWriter, r *http.Request) {
- todos := models.Todos{
- models.Todo{Name: "Write presentation"},
- models.Todo{Name: "Host meetup"},
- }
- w.Header().Set("Content-Type", "application/json; charset=UTF-8")
- w.WriteHeader(http.StatusOK)
- if err := json.NewEncoder(w).Encode(todos); err != nil {
- panic(err)
- }
- }
- var Test = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- fmt.Fprintln(w, "Test:")
- })
- func TodoShow(w http.ResponseWriter, r *http.Request) {
- vars := mux.Vars(r)
- todoId := vars["todoId"]
- fmt.Fprintln(w, "Todo show:", todoId)
- }
|