Votes handles HTTP requests to alternatively show the voting app or to save a vote.
(w http.ResponseWriter, r *http.Request)
| 197 | // Votes handles HTTP requests to alternatively show the voting app or to save a |
| 198 | // vote. |
| 199 | func Votes(w http.ResponseWriter, r *http.Request) { |
| 200 | switch r.Method { |
| 201 | case http.MethodGet: |
| 202 | renderIndex(w, r, getDB()) |
| 203 | case http.MethodPost: |
| 204 | saveVote(w, r, getDB()) |
| 205 | default: |
| 206 | w.WriteHeader(http.StatusMethodNotAllowed) |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | // vote contains a single row from the votes table in the database. Each vote |
| 211 | // includes a candidate ("TABS" or "SPACES") and a timestamp. |