Votes handles HTTP requests to alternatively show the voting app or to save a vote.
(w http.ResponseWriter, r *http.Request)
| 209 | // Votes handles HTTP requests to alternatively show the voting app or to save a |
| 210 | // vote. |
| 211 | func Votes(w http.ResponseWriter, r *http.Request) { |
| 212 | switch r.Method { |
| 213 | case http.MethodGet: |
| 214 | renderIndex(w, r, getDB()) |
| 215 | case http.MethodPost: |
| 216 | saveVote(w, r, getDB()) |
| 217 | default: |
| 218 | w.WriteHeader(http.StatusMethodNotAllowed) |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | // vote contains a single row from the votes table in the database. Each vote |
| 223 | // includes a candidate ("TABS" or "SPACES") and a timestamp. |